Skip to content

Instantly share code, notes, and snippets.

@davidpfahler
Last active December 8, 2015 19:23
Show Gist options
  • Save davidpfahler/c0aebb4de91751f0ea1c to your computer and use it in GitHub Desktop.
Save davidpfahler/c0aebb4de91751f0ea1c to your computer and use it in GitHub Desktop.
Alternative Redux API suggestions without action constants using only functions
import { createStore } from 'redux'
let increment = (state = 0, x) => { return state + x }
let decrement = (state = 0, x) => { return state - x}
let store = createStore([increment, decrement])
store.subscribe(() =>
console.log(store.getState())
)
store.dispatch(increment, 1)
// 1
store.dispatch(increment, 2)
// 3
store.dispatch(decrement, 3)
// 0
import { createStore, createAction } from 'redux'
let increment = createAction((state = 0, x) => { return state + x })
let decrement = createAction((state = 0, x) => { return state - x})
let store = createStore([increment, decrement])
store.subscribe(() =>
console.log(store.getState())
)
increment(1)
// 1
increment(2)
// 3
decrement(3)
// 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment