1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/examples/with-redux/store.js

18 lines
568 B
JavaScript
Raw Normal View History

import { createStore, applyMiddleware } from 'redux'
import thunkMiddleware from 'redux-thunk'
export const reducer = (state = { lastUpdate: 0, light: false }, action) => {
switch (action.type) {
case 'TICK': return { lastUpdate: action.ts, light: !!action.light }
default: return state
}
}
export const startClock = () => dispatch => {
return setInterval(() => dispatch({ type: 'TICK', light: true, ts: Date.now() }), 800)
}
export const initStore = (initialState) => {
return createStore(reducer, initialState, applyMiddleware(thunkMiddleware))
}