forked from code-dot-org/code-dot-org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredux.js
More file actions
39 lines (32 loc) · 780 Bytes
/
redux.js
File metadata and controls
39 lines (32 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { createStore } from '@cdo/apps/redux';
import { combineReducers } from 'redux';
import progress from './progressRedux';
import stageLock from './stageLockRedux';
import hiddenStage from './hiddenStageRedux';
/**
* A module for maintaining the redux store used by code-studio
*/
let reduxStore;
/**
* Get a reference to our redux store. If it doesn't exist yet, create it.
*/
export const getStore = () => {
if (!reduxStore) {
createCodeStudioStore();
}
return reduxStore;
};
/**
* Create our redux store.
*/
const createCodeStudioStore = () => {
if (reduxStore) {
throw new Error('reduxStore already exists');
}
const reducers = combineReducers({
progress,
stageLock,
hiddenStage
});
reduxStore = createStore(reducers);
};