Skip to content

Instantly share code, notes, and snippets.

@osanyin
Created March 16, 2018 21:35
Show Gist options
  • Select an option

  • Save osanyin/26fd0001dd55dc152fd1d3bf7c6d8536 to your computer and use it in GitHub Desktop.

Select an option

Save osanyin/26fd0001dd55dc152fd1d3bf7c6d8536 to your computer and use it in GitHub Desktop.
import { createStore } from 'redux'
import todoApp from './reducers'
import { addTodo, toggleTodo, setVisibilityFilter, VisibilityFilters } from './actions'
let store = createStore(todoApp)
// Log the initial state
console.log(store.getState())
// Every time the state changes, log it
// Note that subscribe() returns a function for unregistering the listener
let unsubscribe = store.subscribe(() =>
console.log(store.getState())
)
// Dispatch some actions
store.dispatch(addTodo('Learn about actions'))
store.dispatch(addTodo('Learn about reducers'))
store.dispatch(addTodo('Learn about store'))
store.dispatch(toggleTodo(0))
store.dispatch(toggleTodo(1))
store.dispatch(setVisibilityFilter(VisibilityFilters.SHOW_COMPLETED))
// Stop listening to state updates
unsubscribe()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment