Skip to content

Commit

Permalink
Call dispatch callback in the scope of the <Routes>
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Oct 11, 2014
1 parent 5a91ce4 commit 7e8e612
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions modules/components/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ var Routes = React.createClass({
this._handleStateChange = this.handleStateChange.bind(this, path, actionType);
this.setState(nextState);
}
}.bind(this));
});
},

handleStateChange: function (path, actionType) {
Expand Down Expand Up @@ -340,15 +340,16 @@ var Routes = React.createClass({
toMatches = nextMatches;
}

var callbackScope = this;
var query = Path.extractQuery(path) || {};

runTransitionFromHooks(fromMatches, transition, function (error) {
if (error || transition.isAborted)
return callback(error, transition.abortReason);
return callback.call(callbackScope, error, transition.abortReason);

runTransitionToHooks(toMatches, transition, query, function (error) {
if (error || transition.isAborted)
return callback(error, transition.abortReason);
return callback.call(callbackScope, error, transition.abortReason);

var matches = currentMatches.slice(0, currentMatches.length - fromMatches.length).concat(toMatches);
var rootMatch = getRootMatch(matches);
Expand All @@ -357,7 +358,7 @@ var Routes = React.createClass({
return match.route;
});

callback(null, null, {
callback.call(callbackScope, null, null, {
path: path,
matches: matches,
activeRoutes: routes,
Expand Down

0 comments on commit 7e8e612

Please sign in to comment.