Skip to content

Commit

Permalink
feat($initialDispatch): assign initialDispatch properly within closure
Browse files Browse the repository at this point in the history
  • Loading branch information
faceyspacey committed Jun 28, 2017
1 parent a1ab33a commit 4613d1a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/connectRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ export default (
let prevState = INITIAL_LOCATION_STATE // used only to pass as 1st arg to `scrollBehavior.updateScroll` if used
let nextState = {} // used as 2nd arg to `scrollBehavior.updateScroll` and to change `document.title`
let prevLength = 1 // used by `historyCreateAction` to calculate if moving along history.entries track
let initialDispatch = () => null

const reducer = createLocationReducer(INITIAL_LOCATION_STATE, routesMap)
const thunk = createThunk(routesMap, locationKey)
const initialDispatch = () => _initialDispatch && _initialDispatch()

const windowDocument: Document = getDocument() // get plain object for window.document if server side

Expand Down Expand Up @@ -398,7 +398,7 @@ export default (
// dispatch the first location-aware action so initial app state is based on the url on load
if (!location.hasSSR || isServer()) {
// only dispatch on client before SSR is setup, which passes state on to the client
initialDispatch = () => {
_initialDispatch = () => {
const action = historyCreateAction(
currentPathname,
routesMap,
Expand All @@ -411,7 +411,7 @@ export default (
}

if (shouldPerformInitialDispatch !== false) {
initialDispatch()
_initialDispatch()
}
}
else {
Expand Down Expand Up @@ -455,6 +455,7 @@ export default (

_history = history
_scrollBehavior = scrollBehavior
let _initialDispatch

_updateScroll = (performedByUser: boolean = true) => {
if (scrollBehavior) {
Expand Down

0 comments on commit 4613d1a

Please sign in to comment.