Skip to content

Instantly share code, notes, and snippets.

@joshuajhun
Created October 27, 2016 14:44
Show Gist options
  • Save joshuajhun/74ae69762b27017e97a67319144a5515 to your computer and use it in GitHub Desktop.
Save joshuajhun/74ae69762b27017e97a67319144a5515 to your computer and use it in GitHub Desktop.
  import {createStore} from 'redux'

  const reducer = (state, action) => {
    switch (action.type) {
      case 'INCREMENT':
        return state = state + action.payload
      case 'DECREMENT':
        return state = state - action.payload
      default:
        return state
    }
  }

  const store = createStore(reducer, 0)

  store.subscribe(()=>{
    console.log('store changed', store.getState())
  })

  store.dispatch({type: 'INCREMENT', payload: 1})
  store.dispatch({type: 'DECREMENT', payload: 6})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment