Created
March 3, 2019 11:19
-
-
Save ondrej-janosik/5140fb342718732d1b60508402e33409 to your computer and use it in GitHub Desktop.
redux-starter-kit createReducer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createAction, createReducer } from 'redux-starter-kit'; | |
/** | |
* Adds marker to the map. Payload: marker data | |
*/ | |
export const addMarker = createAction('map/add-marker'); | |
/** | |
* Toggles marker visibility | |
*/ | |
export const toggleMarkerVisibility = createAction( | |
'map/toggle-marker-visibility', | |
); | |
const initialState = { | |
markers: [], | |
initialLocation: { | |
latitude: 49.19522, | |
Longitude: 16.60796, | |
}, | |
}; | |
export const mapReducer = createReducer(initialState, { | |
[addMarker]: (state, action) => { | |
const newMarker = action.payload; | |
state.markers.push(newMarker); | |
}, | |
[toggleMarkerVisibility]: (state, action) => { | |
const index = action.payload; | |
const marker = state.markers[index]; | |
marker.visible = !marker.visible; | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment