forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.js
44 lines (41 loc) · 888 Bytes
/
store.js
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
import { createStore, applyMiddleware } from 'redux'
import { composeWithDevTools } from 'redux-devtools-extension'
const initialState = {
lastUpdate: 0,
light: false,
count: 0,
}
const reducer = (state = initialState, action) => {
switch (action.type) {
case 'TICK':
return {
...state,
lastUpdate: action.lastUpdate,
light: !!action.light,
}
case 'INCREMENT':
return {
...state,
count: state.count + 1,
}
case 'DECREMENT':
return {
...state,
count: state.count - 1,
}
case 'RESET':
return {
...state,
count: initialState.count,
}
default:
return state
}
}
export const initializeStore = (preloadedState = initialState) => {
return createStore(
reducer,
preloadedState,
composeWithDevTools(applyMiddleware())
)
}