Skip to content

Instantly share code, notes, and snippets.

@kevinrutherford
Last active April 23, 2018 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinrutherford/9490440aadb55eff3bb825d297bdf630 to your computer and use it in GitHub Desktop.
Save kevinrutherford/9490440aadb55eff3bb825d297bdf630 to your computer and use it in GitHub Desktop.
import deepFreeze from 'deep-freeze'
import configureStore from '../app/store/'
export const reduce = (actions) => {
const store = configureStore()
actions.forEach(action => store.dispatch(action))
return store.getState()
}
export const reductio = (reducer, actions) => {
var state = reducer(undefined, {type: 'NO_SUCH_ACTION'})
return apply(reducer, state, actions)
}
export const apply = (reducer, initialState, actions) => {
let state = initialState
for (var action of actions) {
deepFreeze(state)
state = reducer(state, action)
}
return state
}
switch (process.env.NODE_ENV) {
case 'production':
module.exports = require('./configureStore.prod')
break
case 'test':
module.exports = require('./configureStore.test')
break
default:
module.exports = require('./configureStore.dev')
break
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment