Skip to content

Instantly share code, notes, and snippets.

@goatslacker
Created June 4, 2015 05:27
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goatslacker/2653c4024aecec911c73 to your computer and use it in GitHub Desktop.
Save goatslacker/2653c4024aecec911c73 to your computer and use it in GitHub Desktop.
Writing a simple store as a reducer
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