Skip to content

Commit 0968148

Browse files
committed
steal the store from redux
1 parent 9f6ac1a commit 0968148

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/store/reducer.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
import { combineReducers } from 'redux'
22

3+
export const ATTACH_REDUCER = '@KEA/ATTACH_REDUCER'
4+
35
// worker functions are loaded globally, reducers locally in store
46
let defaultReducerRoot = null
57

68
// all reducers that are created
79
let reducerTree = {}
810
let rootReducers = {}
9-
let syncedWithStore = {}
11+
let syncedWithStore = {} // TODO: remove?
12+
let store
1013

1114
const defaultState = {}
1215

16+
export function attachStore (storeReference) {
17+
store = storeReference
18+
}
19+
1320
export function clearReducerCache () {
1421
defaultReducerRoot = null
1522
reducerTree = {}
@@ -78,6 +85,7 @@ export function addReducer (path, reducer) {
7885
}
7986

8087
regenerateRootReducer(pathStart)
88+
store && store.dispatch({ type: ATTACH_REDUCER, payload: { path, reducer } })
8189
}
8290

8391
export function regenerateRootReducer (pathStart) {

src/store/store.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createStore, applyMiddleware, combineReducers, compose } from 'redux'
22

3-
import { keaReducer } from './reducer'
3+
import { keaReducer, attachStore } from './reducer'
44
// import { globalPlugins, activatePlugin } from '../plugins'
55

66
const reduxDevToolsCompose = typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
@@ -51,6 +51,11 @@ export function getStore (opts = {}) {
5151
// create store
5252
const store = finalCreateStore(combinedReducers, Object.assign({}, options.preloadedState))
5353

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+
5459
// // run post-hooks
5560
// globalPlugins.afterReduxStore.forEach(f => f(options, store))
5661

0 commit comments

Comments
 (0)