Skip to content

Commit d12e9de

Browse files
gaearonryanflorence
authored andcommitted
Use Router instead of this now that autobinding is off
1 parent cbbda91 commit d12e9de

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

modules/createRouter.js

+27-27
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ function createRouter(options) {
173173
},
174174

175175
clearAllRoutes: function () {
176-
this.cancelPendingTransition();
177-
this.namedRoutes = {};
178-
this.routes = [];
176+
Router.cancelPendingTransition();
177+
Router.namedRoutes = {};
178+
Router.routes = [];
179179
},
180180

181181
/**
@@ -185,18 +185,18 @@ function createRouter(options) {
185185
if (isReactChildren(routes))
186186
routes = createRoutesFromReactChildren(routes);
187187

188-
addRoutesToNamedRoutes(routes, this.namedRoutes);
188+
addRoutesToNamedRoutes(routes, Router.namedRoutes);
189189

190-
this.routes.push.apply(this.routes, routes);
190+
Router.routes.push.apply(Router.routes, routes);
191191
},
192192

193193
/**
194194
* Replaces routes of this router from the given children object (see ReactChildren).
195195
*/
196196
replaceRoutes: function (routes) {
197-
this.clearAllRoutes();
198-
this.addRoutes(routes);
199-
this.refresh();
197+
Router.clearAllRoutes();
198+
Router.addRoutes(routes);
199+
Router.refresh();
200200
},
201201

202202
/**
@@ -205,7 +205,7 @@ function createRouter(options) {
205205
* match can be made.
206206
*/
207207
match: function (path) {
208-
return Match.findMatch(this.routes, path);
208+
return Match.findMatch(Router.routes, path);
209209
},
210210

211211
/**
@@ -217,7 +217,7 @@ function createRouter(options) {
217217
if (PathUtils.isAbsolute(to)) {
218218
path = to;
219219
} else {
220-
var route = (to instanceof Route) ? to : this.namedRoutes[to];
220+
var route = (to instanceof Route) ? to : Router.namedRoutes[to];
221221

222222
invariant(
223223
route instanceof Route,
@@ -236,7 +236,7 @@ function createRouter(options) {
236236
* to the route with the given name, URL parameters, and query.
237237
*/
238238
makeHref: function (to, params, query) {
239-
var path = this.makePath(to, params, query);
239+
var path = Router.makePath(to, params, query);
240240
return (location === HashLocation) ? '#' + path : path;
241241
},
242242

@@ -245,7 +245,7 @@ function createRouter(options) {
245245
* a new URL onto the history stack.
246246
*/
247247
transitionTo: function (to, params, query) {
248-
var path = this.makePath(to, params, query);
248+
var path = Router.makePath(to, params, query);
249249

250250
if (pendingTransition) {
251251
// Replace so pending location does not stay in history.
@@ -260,7 +260,7 @@ function createRouter(options) {
260260
* the current URL in the history stack.
261261
*/
262262
replaceWith: function (to, params, query) {
263-
location.replace(this.makePath(to, params, query));
263+
location.replace(Router.makePath(to, params, query));
264264
},
265265

266266
/**
@@ -292,7 +292,7 @@ function createRouter(options) {
292292
if (abortReason instanceof Cancellation) {
293293
return;
294294
} else if (abortReason instanceof Redirect) {
295-
location.replace(this.makePath(abortReason.to, abortReason.params, abortReason.query));
295+
location.replace(Router.makePath(abortReason.to, abortReason.params, abortReason.query));
296296
} else {
297297
location.pop();
298298
}
@@ -304,7 +304,7 @@ function createRouter(options) {
304304
},
305305

306306
handleLocationChange: function (change) {
307-
this.dispatch(change.path, change.type);
307+
Router.dispatch(change.path, change.type);
308308
},
309309

310310
/**
@@ -324,7 +324,7 @@ function createRouter(options) {
324324
* hooks wait, the transition is fully synchronous.
325325
*/
326326
dispatch: function (path, action) {
327-
this.cancelPendingTransition();
327+
Router.cancelPendingTransition();
328328

329329
var prevPath = state.path;
330330
var isRefreshing = action == null;
@@ -335,9 +335,9 @@ function createRouter(options) {
335335
// Record the scroll position as early as possible to
336336
// get it before browsers try update it automatically.
337337
if (prevPath && action === LocationActions.PUSH)
338-
this.recordScrollPosition(prevPath);
338+
Router.recordScrollPosition(prevPath);
339339

340-
var match = this.match(path);
340+
var match = Router.match(path);
341341

342342
warning(
343343
match != null,
@@ -370,7 +370,7 @@ function createRouter(options) {
370370
toRoutes = nextRoutes;
371371
}
372372

373-
var transition = new Transition(path, this.replaceWith.bind(this, path));
373+
var transition = new Transition(path, Router.replaceWith.bind(Router, path));
374374
pendingTransition = transition;
375375

376376
var fromComponents = mountedComponents.slice(prevRoutes.length - fromRoutes.length);
@@ -401,7 +401,7 @@ function createRouter(options) {
401401
*/
402402
run: function (callback) {
403403
invariant(
404-
!this.isRunning,
404+
!Router.isRunning,
405405
'Router is already running'
406406
);
407407

@@ -417,32 +417,32 @@ function createRouter(options) {
417417
if (transition.abortReason) {
418418
Router.handleAbort(transition.abortReason);
419419
} else {
420-
callback.call(this, this, nextState = newState);
420+
callback.call(Router, Router, nextState = newState);
421421
}
422422
};
423423

424424
if (!(location instanceof StaticLocation)) {
425425
if (location.addChangeListener)
426-
location.addChangeListener(Router.handleLocationChange.bind(Router));
426+
location.addChangeListener(Router.handleLocationChange);
427427

428-
this.isRunning = true;
428+
Router.isRunning = true;
429429
}
430430

431431
// Bootstrap using the current path.
432-
this.refresh();
432+
Router.refresh();
433433
},
434434

435435
refresh: function () {
436436
Router.dispatch(location.getCurrentPath(), null);
437437
},
438438

439439
stop: function () {
440-
this.cancelPendingTransition();
440+
Router.cancelPendingTransition();
441441

442442
if (location.removeChangeListener)
443-
location.removeChangeListener(Router.handleLocationChange.bind(Router));
443+
location.removeChangeListener(Router.handleLocationChange);
444444

445-
this.isRunning = false;
445+
Router.isRunning = false;
446446
},
447447

448448
getLocation: function () {

0 commit comments

Comments
 (0)