Last active
March 21, 2017 00:01
-
-
Save StevenJL/4d635bfadbbc9f161ec8 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
| // instantiate the store | |
| const store = createStore(todoApp, window.STATE_FROM_SERVER) | |
| // import the action creators | |
| import { addTodo, completeTodo, setVisibilityFilter } | |
| // `store.subscribe()` takes an anonymous function that will be invoked | |
| // everytime the store state changes. It returns another method, which when | |
| // invoked, will stop listening. | |
| let unsubscribe = store.subscribe(() => | |
| console.log(store.getState()) | |
| ) | |
| // dispatch the actions | |
| // under the hood, the store will call the reducer function you defined | |
| // the store will pass in the current state and the dispatched action | |
| // to the reducer | |
| store.dispatch(addTodo("Write letter of apology to mime")) | |
| store.dispatch(addTodo("Cure athlete's foot in 3rd world countries")) | |
| store.dispatch(completeTodo(0)) | |
| store.dispatch(completeTodo(1)) | |
| store.dispatch(setVisibilityFilter("SHOW_COMPLETED") | |
| // stop listening to state changes | |
| unsubscribe() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment