From db6b501966d9f063d37cd45f21096249579535c5 Mon Sep 17 00:00:00 2001 From: Joel Chen Date: Thu, 6 Feb 2020 00:27:14 -0800 Subject: [PATCH] minor fix for initial state handling --- packages/subapp-redux/src/shared.js | 11 ++++++----- packages/subapp-web/src/index.js | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/subapp-redux/src/shared.js b/packages/subapp-redux/src/shared.js index acf63da3e..33e55088c 100644 --- a/packages/subapp-redux/src/shared.js +++ b/packages/subapp-redux/src/shared.js @@ -92,7 +92,7 @@ function createSharedStore(initialState, info, storeContainer) { if (store) { // TODO: redux doesn't have a way to set initial state // after store's created? What can we do about this? - replaceReducer(info.reduxReducers, info); + replaceReducer(info.reduxReducers, info, storeContainer); } else { reducerContainer = newReducerContainer(); store = createStore( @@ -101,10 +101,11 @@ function createSharedStore(initialState, info, storeContainer) { ); store[originalReplaceReducerSym] = store.replaceReducer; // - // TODO: monkey patching store is bad - // since this is share store, reducers must be replaced - // as object of named reducers also, but patching an API - // that alters argument type is worst + // TODO: better handling of a replaceReducer that takes extra params + // + // Since this is share store, reducers must be replaced + // as object of named reducers also. + // // Maybe create a proxy store object, one for each sub-app // // NOTE: It's only on SSR that we need to share store within the diff --git a/packages/subapp-web/src/index.js b/packages/subapp-web/src/index.js index 3020a363b..39c0c84c4 100644 --- a/packages/subapp-web/src/index.js +++ b/packages/subapp-web/src/index.js @@ -72,9 +72,9 @@ export function loadSubApp(info, renderStart) { if (!instance._prepared) { if (subApp.info.prepare) { - instance._prepared = subApp.info.prepare(subApp.info, instance); + instance._prepared = subApp.info.prepare(subApp.info, instance, options); } else { - instance._prepared = {}; + instance._prepared = options.initialState || {}; } }