Last active
December 8, 2015 19:23
-
-
Save davidpfahler/c0aebb4de91751f0ea1c to your computer and use it in GitHub Desktop.
Alternative Redux API suggestions without action constants using only functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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