-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreducer.js
More file actions
49 lines (45 loc) · 1.27 KB
/
reducer.js
File metadata and controls
49 lines (45 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import * as actions from "./actionTypes";
import positionData from "./positionData";
export function myReducer(
state = {
name: "InitialState",
metaData: "No Data Input as of yet",
longitude: 103.851959,
latitude: 1.4027,
longitudeDelta: 0.0922,
latitudeDelta: 0.0421,
starred: false,
},
action
) {
switch (action.type) {
case actions.SELECT_LOCATION:
return {
...state,
name: action.payload.name,
longitude: action.payload.longitude,
latitude: action.payload.latitude,
metaData: action.payload.metaData,
starred: action.payload.starred,
};
default:
console.log("nothing Changed");
return state;
}
}
export function starReducer(state = positionData, action) {
switch (action.type) {
case actions.ADD_STARRED_LIST:
let stringifiedData = JSON.stringify(state);
let copyOfPositionData = JSON.parse(stringifiedData);
let starToBeToggled = copyOfPositionData.filter(
(element) => element.name === action.payload.name
);
starToBeToggled[0].starred = !action.payload.starred;
console.log("COPYCOPYCOPY: ", copyOfPositionData);
return copyOfPositionData;
default:
console.log("nothing Changed");
return state;
}
}