forked from zoltantothcom/Design-Patterns-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (44 loc) · 1.07 KB
/
index.js
File metadata and controls
48 lines (44 loc) · 1.07 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
import {
SUBMIT,
TOGGLE,
TOGGLE_JS,
TOGGLE_MODE,
START,
RESTART
} from '../static/constants/actions';
import { randomFromRange } from '../helpers/randomFromRange';
const rootReducer = (state, action) => {
switch (action.type) {
case SUBMIT:
const { recentlyAnswered, remainingPatterns, currentIndex } = action.payload;
const current = remainingPatterns.length ? remainingPatterns[currentIndex] : null;
return {
...state,
progress: {
answers: state.progress.answers.concat(recentlyAnswered),
remaining: remainingPatterns,
current
}
};
case TOGGLE:
return state;
case TOGGLE_JS:
return { ...state, js: action.payload };
case TOGGLE_MODE:
return { ...state, mode: action.payload };
case START:
return { ...state, intro: false };
case RESTART:
return {
...state,
progress: {
answers: [],
remaining: state.patterns,
current: state.patterns[randomFromRange(state.patterns.length)]
}
};
default:
return state;
}
};
export default rootReducer;