Created
March 16, 2018 21:35
-
-
Save osanyin/26fd0001dd55dc152fd1d3bf7c6d8536 to your computer and use it in GitHub Desktop.
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 { 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