Skip to content

Instantly share code, notes, and snippets.

@vzaidman
Created December 8, 2017 12:42
Show Gist options
  • Save vzaidman/b0d233163534d3e68562cb0074a68edd to your computer and use it in GitHub Desktop.
Save vzaidman/b0d233163534d3e68562cb0074a68edd to your computer and use it in GitHub Desktop.
import { ordersReducer } from './oreders-reducer'
import { fetchOrders, addOrder, updateOrder, fetchProfile } from './actions'
import { getState, dispatch } from './store'
dispatch({ TYPE: '@@INIT' })
console.log(getState())
// the initial state is { data: [], loading: false }
// when we dispatch the "fetchOrders" action, an api call to fetch orders is made
// the state becomes { data: [], loading: true }
await dispatch(fetchOrders())
// then, when the fetching ends
console.log(getState())
// the state becomes { data: ['order1', 'order2'], loading: false }
// later, when we logout:
await dispatch(logout())
console.log(getState())
// { data: undefined, loading: false }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment