in src/reducers/root.js [31:96]
export function provideInitialState(initialState) {
const coreReducer = coreReducerFactory(initialState);
const handleRegisterEntry = (
state,
{
payload: {
id,
mint,
mapboxApiAccessToken,
mapboxApiUrl,
mapStylesReplaceDefault,
initialUiState
}
}
) => {
// by default, always create a mint state even if the same id already exist
// if state.id exist and mint=false, keep the existing state
const previousState = state[id] && mint === false ? state[id] : undefined;
return {
// register entry to kepler.gl passing in mapbox config to mapStyle
...state,
[id]: coreReducer(
previousState,
keplerGlInit({mapboxApiAccessToken, mapboxApiUrl, mapStylesReplaceDefault, initialUiState})
)
};
};
const handleDeleteEntry = (state, {payload: id}) =>
Object.keys(state).reduce(
(accu, curr) => ({
...accu,
...(curr === id ? {} : {[curr]: state[curr]})
}),
{}
);
const handleRenameEntry = (state, {payload: {oldId, newId}}) =>
Object.keys(state).reduce(
(accu, curr) => ({
...accu,
...{[curr === oldId ? newId : curr]: state[curr]}
}),
{}
);
return (state = initialCoreState, action) => {
// update child states
Object.keys(state).forEach(id => {
const updateItemState = coreReducer(state[id], _actionFor(id, action));
state = _updateProperty(state, id, updateItemState);
});
// perform additional state reducing (e.g. switch action.type etc...)
return handleActions(
{
[ActionTypes.REGISTER_ENTRY]: handleRegisterEntry,
[ActionTypes.DELETE_ENTRY]: handleDeleteEntry,
[ActionTypes.RENAME_ENTRY]: handleRenameEntry
},
initialCoreState
)(state, action);
};
}