-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathindex.js
More file actions
54 lines (46 loc) · 1.03 KB
/
index.js
File metadata and controls
54 lines (46 loc) · 1.03 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import {
createStore,
applyMiddleware,
compose
} from 'redux';
const uuid = require('uuid/v4');
import reducer from '../reducers/index';
import patterns from '../static/patterns';
import middleware from '../middleware';
import {
loadState,
saveState
} from '../helpers/localStorage';
export const answers = patterns.map(pattern => ({
...pattern,
answered: false,
correct: null,
answerId: null,
uuid: uuid()
}));
export const initialProgress = {
answers: [],
remaining: answers,
current: answers[0]
};
export const initialState = {
js: 'es5',
mode: 'dark',
intro: true,
patterns: answers,
progress: initialProgress
};
const state = {
...initialState,
...loadState()
};
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = createStore(reducer, state, composeEnhancers(applyMiddleware(...middleware)));
store.subscribe(() => {
const currentState = store.getState();
saveState({
mode: currentState.mode,
js: currentState.js
});
});
export default store;