File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change 1
1
import { combineReducers } from 'redux'
2
2
3
+ export const ATTACH_REDUCER = '@KEA/ATTACH_REDUCER'
4
+
3
5
// worker functions are loaded globally, reducers locally in store
4
6
let defaultReducerRoot = null
5
7
6
8
// all reducers that are created
7
9
let reducerTree = { }
8
10
let rootReducers = { }
9
- let syncedWithStore = { }
11
+ let syncedWithStore = { } // TODO: remove?
12
+ let store
10
13
11
14
const defaultState = { }
12
15
16
+ export function attachStore ( storeReference ) {
17
+ store = storeReference
18
+ }
19
+
13
20
export function clearReducerCache ( ) {
14
21
defaultReducerRoot = null
15
22
reducerTree = { }
@@ -78,6 +85,7 @@ export function addReducer (path, reducer) {
78
85
}
79
86
80
87
regenerateRootReducer ( pathStart )
88
+ store && store . dispatch ( { type : ATTACH_REDUCER , payload : { path, reducer } } )
81
89
}
82
90
83
91
export function regenerateRootReducer ( pathStart ) {
Original file line number Diff line number Diff line change 1
1
import { createStore , applyMiddleware , combineReducers , compose } from 'redux'
2
2
3
- import { keaReducer } from './reducer'
3
+ import { keaReducer , attachStore } from './reducer'
4
4
// import { globalPlugins, activatePlugin } from '../plugins'
5
5
6
6
const reduxDevToolsCompose = typeof window !== 'undefined' && window . __REDUX_DEVTOOLS_EXTENSION_COMPOSE__
@@ -51,6 +51,11 @@ export function getStore (opts = {}) {
51
51
// create store
52
52
const store = finalCreateStore ( combinedReducers , Object . assign ( { } , options . preloadedState ) )
53
53
54
+ // give kea direct access to this store
55
+ // we need this to dispatch hydration actions when new kea logic stores are
56
+ // injected together with react components
57
+ attachStore ( store )
58
+
54
59
// // run post-hooks
55
60
// globalPlugins.afterReduxStore.forEach(f => f(options, store))
56
61
You can’t perform that action at this time.
0 commit comments