redux-first-router
Version:
think of your app in states not routes (and, yes, while keeping the address bar in sync)
19 lines (15 loc) • 509 B
Flow
// @flow
import type { Store } from 'redux'
import type { RoutesMap, SelectLocationState, Bag } from '../flow-types'
export default (
routesMap: RoutesMap,
selectLocationState: SelectLocationState,
bag: Bag
) => ({ dispatch, getState }: Store<*, *>): Promise<*> => {
const { type } = selectLocationState(getState())
const route = routesMap[type]
if (route && typeof route.thunk === 'function') {
return Promise.resolve(route.thunk(dispatch, getState, bag))
}
return Promise.resolve()
}