Skip to content

Instantly share code, notes, and snippets.

@donabrams
Last active September 15, 2016 19:12
Show Gist options
  • Save donabrams/b1fb153603a2ebfc35bef07b42db05b5 to your computer and use it in GitHub Desktop.
Save donabrams/b1fb153603a2ebfc35bef07b42db05b5 to your computer and use it in GitHub Desktop.
Alternative Redux reducer syntax
import { ACTION1, ACTION2 } from './someAction'
import { reducer } from 'alt-redux'
export const name = "TODOS"
const initialState = {}
const store = reducer({ name, initialState })
store.on(ACTION1, (state, { foo, bar }) => ({...state, foo, bar }))
store.on(ACTION2, (state, { baz }) => ({...state, baz }))
export default reducer
import { ACTION1, ACTION2 } from './someAction'
import { reducer } from 'alt-redux'
export const name = "TODOS"
const initialState = {}
export default reducer({ name, initialState, handlers: {
[ACTION1]: (state, { foo, bar }) => ({...state, foo, bar })),
[ACTION2]: (state, { baz }) => ({...state, baz }),
}});
import { ACTION1, ACTION2 } from './someAction'
const initialState = {}
const reducer = {
[ACTION1]: (state = initialState, { foo, bar }) => ({...state, foo, bar }),
[ACTION2]: (state = initialState, { baz }) => ({...state, baz }),
}
export default reducer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment