Skip to content

Commit 41149ab

Browse files
committed
Refactor computeNextState
1 parent 50ea54c commit 41149ab

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

modules/components/Routes.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,7 @@ function hasMatch(matches, match) {
7575
* callback(error, nextState) when finished. Also runs all
7676
* transition hooks along the way.
7777
*/
78-
function computeNextState(component, transition, callback) {
79-
if (component.state.path === transition.path)
80-
return callback(); // Nothing to do!
81-
82-
var currentMatches = component.state.matches;
83-
var nextMatches = component.match(transition.path);
84-
85-
warning(
86-
nextMatches,
87-
'No route matches path "' + transition.path + '". Make sure you have ' +
88-
'<Route path="' + transition.path + '"> somewhere in your routes'
89-
);
90-
91-
if (!nextMatches)
92-
nextMatches = [];
93-
78+
function computeNextState(currentMatches, nextMatches, transition, callback) {
9479
var fromMatches, toMatches;
9580
if (currentMatches.length) {
9681
fromMatches = currentMatches.filter(function (match) {
@@ -354,9 +339,20 @@ var Routes = React.createClass({
354339
* the transition. To resolve asynchronously, they may use transition.wait(promise).
355340
*/
356341
dispatch: function (path, callback) {
342+
if (this.state.path === path)
343+
return callback(); // Nothing to do!
344+
357345
var transition = new Transition(this, path);
346+
var currentMatches = this.state.matches || [];
347+
var nextMatches = this.match(path) || [];
348+
349+
warning(
350+
nextMatches,
351+
'No route matches path "%s". Make sure you have <Route path="%s"> somewhere in your routes',
352+
path, path
353+
);
358354

359-
computeNextState(this, transition, function (error, nextState) {
355+
computeNextState(currentMatches, nextMatches, transition, function (error, nextState) {
360356
if (error || transition.isAborted || nextState == null)
361357
return callback(error, transition.abortReason);
362358

0 commit comments

Comments
 (0)