Created
June 4, 2015 05:27
-
-
Save goatslacker/2653c4024aecec911c73 to your computer and use it in GitHub Desktop.
Writing a simple store as a reducer
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 Alt from 'alt' | |
const alt = new Alt() | |
const CounterActions = alt.createActions({ | |
inc: x => x, | |
dec: x => x, | |
}); | |
const CounterStore = alt.createStore({ | |
displayName: 'CounterStore', | |
state: { counter: 0 }, | |
reduce(state, { action }) { | |
if (action === CounterActions.INC) { | |
return { counter: state.counter + 1 } | |
} else if (action === CounterActions.DEC) { | |
return { counter: state.counter - 1 } | |
} else { | |
return state | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment