-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fixed] rendering current handlers before rendering root
when the path changes, the router figures out the next state, but we don't want the current views using it until the root handler is rendered again, allowing people to put up loading indicators, or have live data not break their apps
- Loading branch information
1 parent
0a01447
commit b75f648
Showing
4 changed files
with
74 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,6 +138,12 @@ function createRouter(options) { | |
var onError = options.onError || defaultErrorHandler; | ||
var onAbort = options.onAbort || defaultAbortHandler; | ||
var state = {}; | ||
var nextState = {}; | ||
|
||
function updateState() { | ||
state = nextState; | ||
This comment has been minimized.
Sorry, something went wrong.
mjackson
Member
|
||
nextState = {}; | ||
} | ||
|
||
// Automatically fall back to full page refreshes in | ||
// browsers that don't support the HTML history API. | ||
|
@@ -302,11 +308,11 @@ function createRouter(options) { | |
if (error || transition.isAborted) | ||
return callback.call(router, error, transition); | ||
|
||
state.path = path; | ||
state.action = action; | ||
state.routes = nextRoutes; | ||
state.params = nextParams; | ||
state.query = nextQuery; | ||
nextState.path = path; | ||
nextState.action = action; | ||
nextState.routes = nextRoutes; | ||
nextState.params = nextParams; | ||
nextState.query = nextQuery; | ||
|
||
callback.call(router, null, transition); | ||
}); | ||
|
@@ -327,7 +333,7 @@ function createRouter(options) { | |
} else if (transition.isAborted) { | ||
onAbort.call(router, transition.abortReason, location); | ||
} else { | ||
callback.call(router, router, state); | ||
callback.call(router, router, nextState); | ||
} | ||
} | ||
|
||
|
@@ -384,10 +390,12 @@ function createRouter(options) { | |
}, | ||
|
||
getInitialState: function () { | ||
updateState(); | ||
return state; | ||
}, | ||
|
||
componentWillReceiveProps: function () { | ||
updateState(); | ||
this.setState(state); | ||
}, | ||
|
||
|
Yay for tests! 💃