Skip to content

Instantly share code, notes, and snippets.

@aamnah
Created December 2, 2016 08:33
Show Gist options
  • Select an option

  • Save aamnah/f9c533fe0d02841b0ffdf390f4969e8d to your computer and use it in GitHub Desktop.

Select an option

Save aamnah/f9c533fe0d02841b0ffdf390f4969e8d to your computer and use it in GitHub Desktop.
Basic Redux functions
// define a reducer
const reducer = function(state, action) {
if (action.type === 'INC') {
return state + action.payload
} else if (action.type === 'DEC') {
return state - action.payload
}
return state
}
// create the store, pass it the reducer
const store = createStore(reducer, 0)
// Subscribe to store changes
store.subscribe(() => {
console.log('store changed', store.getState())
})
// Send actions
store.dispatch({
type: 'INC',
payload: 199
})
store.dispatch({
type: 'DEC',
payload: 575658
})
store.dispatch({
type: 'INC',
payload: 191027
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment