Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[Enhancement] Use preserved state to apply keplerGlInit. when mint=false (#649)

Shan He642c64680914
diff --git a/src/reducers/root.js b/src/reducers/root.js
index 24659d9f4..2eb0afea1 100644
--- a/src/reducers/root.js
+++ b/src/reducers/root.js
@@ -31,15 +31,18 @@ const initialCoreState = {};
export function provideInitialState(initialState) {
const coreReducer = coreReducerFactory(initialState);
- const handleRegisterEntry = (state, {payload: {id, mint, mapboxApiAccessToken, mapboxApiUrl, mapStylesReplaceDefault}}) => ({
- // register a new entry to voyager reducer
+ const handleRegisterEntry = (state, {payload: {id, mint, mapboxApiAccessToken, mapboxApiUrl, mapStylesReplaceDefault}}) => {
+
// 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
- ...state,
- [id]: state[id] && mint === false ? state[id] : {
- ...coreReducer(undefined, keplerGlInit({mapboxApiAccessToken, mapboxApiUrl, mapStylesReplaceDefault}))
+ 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}))
}
- });
+ };
const handleDeleteEntry = (state, {payload: id}) =>
Object.keys(state).reduce(