1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 const createStore = require("resource://devtools/client/shared/redux/create-store.js");
10 } = require("resource://devtools/client/shared/vendor/redux.js");
11 // Reducers which need to be available immediately when the Inspector loads.
13 // Provide a dummy default reducer.
14 // Redux throws an error when calling combineReducers() with an empty object.
15 default: (state = {}) => state,
18 function createReducer(laterReducers = {}) {
19 return combineReducers({
25 module.exports = inspector => {
26 const store = createStore(createReducer(), {
27 // Enable log middleware in tests
29 // Pass the client inspector instance so thunks (dispatched functions)
30 // can access it from their arguments
31 thunkOptions: { inspector },
34 // Map of registered reducers loaded on-demand.
35 store.laterReducers = {};
38 * Augment the current Redux store with a slice reducer.
39 * Call this method to add reducers on-demand after the initial store creation.
43 * @param {Function} reducer
44 * Slice reducer function.
46 store.injectReducer = (key, reducer) => {
47 if (store.laterReducers[key]) {
48 console.log(`Already loaded reducer: ${key}`);
51 store.laterReducers[key] = reducer;
52 store.replaceReducer(createReducer(store.laterReducers));