@@ -3,7 +3,6 @@ var warning = require('react/lib/warning');
3
3
var invariant = require ( 'react/lib/invariant' ) ;
4
4
var canUseDOM = require ( 'react/lib/ExecutionEnvironment' ) . canUseDOM ;
5
5
var copyProperties = require ( 'react/lib/copyProperties' ) ;
6
- var PathStore = require ( '../stores/PathStore' ) ;
7
6
var HashLocation = require ( '../locations/HashLocation' ) ;
8
7
var reversedArray = require ( '../utils/reversedArray' ) ;
9
8
var Transition = require ( '../utils/Transition' ) ;
@@ -264,13 +263,11 @@ function computeHandlerProps(matches, query) {
264
263
265
264
var BrowserTransitionHandling = {
266
265
267
- handleTransitionError : function ( component , error ) {
266
+ handleError : function ( component , error ) {
268
267
throw error ; // This error probably originated in a transition hook.
269
268
} ,
270
269
271
- handleAbortedTransition : function ( component , transition ) {
272
- var reason = transition . abortReason ;
273
-
270
+ handleAbort : function ( component , reason ) {
274
271
if ( reason instanceof Redirect ) {
275
272
component . replaceWith ( reason . to , reason . params , reason . query ) ;
276
273
} else {
@@ -282,11 +279,11 @@ var BrowserTransitionHandling = {
282
279
283
280
var ServerTransitionHandling = {
284
281
285
- handleTransitionError : function ( component , error ) {
282
+ handleError : function ( component , error ) {
286
283
// TODO
287
284
} ,
288
285
289
- handleAbortedTransition : function ( component , transition ) {
286
+ handleAbort : function ( component , reason ) {
290
287
// TODO
291
288
}
292
289
@@ -312,7 +309,6 @@ var Routes = React.createClass({
312
309
mixins : [ ActiveContext , LocationContext , RouteContext , ScrollContext ] ,
313
310
314
311
propTypes : {
315
- initialPath : React . PropTypes . string ,
316
312
onChange : React . PropTypes . func
317
313
} ,
318
314
@@ -322,44 +318,6 @@ var Routes = React.createClass({
322
318
} ;
323
319
} ,
324
320
325
- componentWillMount : function ( ) {
326
- this . handlePathChange ( this . props . initialPath ) ;
327
- } ,
328
-
329
- componentDidMount : function ( ) {
330
- PathStore . addChangeListener ( this . handlePathChange ) ;
331
- } ,
332
-
333
- componentWillUnmount : function ( ) {
334
- PathStore . removeChangeListener ( this . handlePathChange ) ;
335
- } ,
336
-
337
- handlePathChange : function ( _path ) {
338
- var path = _path || PathStore . getCurrentPath ( ) ;
339
- var actionType = PathStore . getCurrentActionType ( ) ;
340
-
341
- if ( this . state . path === path )
342
- return ; // Nothing to do!
343
-
344
- if ( this . state . path )
345
- this . recordScroll ( this . state . path ) ;
346
-
347
- var self = this ;
348
-
349
- this . dispatch ( path , function ( error , transition ) {
350
- if ( error ) {
351
- TransitionHandling . handleTransitionError ( self , error ) ;
352
- } else if ( transition . isAborted ) {
353
- TransitionHandling . handleAbortedTransition ( self , transition ) ;
354
- } else {
355
- self . updateScroll ( path , actionType ) ;
356
-
357
- if ( self . props . onChange )
358
- self . props . onChange . call ( self ) ;
359
- }
360
- } ) ;
361
- } ,
362
-
363
321
/**
364
322
* Performs a depth-first search for the first route in the tree that matches on
365
323
* the given path. Returns an array of all routes in the tree leading to the one
@@ -381,10 +339,32 @@ var Routes = React.createClass({
381
339
return findMatches ( Path . withoutQuery ( path ) , this . getRoutes ( ) , this . props . defaultRoute , this . props . notFoundRoute ) ;
382
340
} ,
383
341
342
+ updateLocation : function ( path , actionType ) {
343
+ if ( this . state . path === path )
344
+ return ; // Nothing to do!
345
+
346
+ if ( this . state . path )
347
+ this . recordScroll ( this . state . path ) ;
348
+
349
+ this . dispatch ( path , actionType , function ( error , abortReason ) {
350
+ if ( error ) {
351
+ TransitionHandling . handleError ( this , error ) ;
352
+ } else if ( abortReason ) {
353
+ TransitionHandling . handleAbort ( this , abortReason ) ;
354
+ } else {
355
+ this . updateScroll ( path , actionType ) ;
356
+
357
+ if ( this . props . onChange )
358
+ this . props . onChange . call ( this ) ;
359
+ }
360
+ } . bind ( this ) ) ;
361
+ } ,
362
+
384
363
/**
385
- * Performs a transition to the given path and calls callback(error, transition)
386
- * with the Transition object when the transition is finished and the component's
387
- * state has been updated accordingly.
364
+ * Performs a transition to the given path and calls callback(error, abortReason)
365
+ * when the transition is finished and the component's state has been updated. If
366
+ * there was an error, the first argument will not be null. Otherwise, if the
367
+ * transition was aborted for some reason, it will be given in the second arg.
388
368
*
389
369
* In a transition, the router first determines which routes are involved by
390
370
* beginning with the current route, up the route tree to the first parent route
@@ -398,16 +378,13 @@ var Routes = React.createClass({
398
378
*/
399
379
dispatch : function ( path , callback ) {
400
380
var transition = new Transition ( this , path ) ;
401
- var self = this ;
402
381
403
382
computeNextState ( this , transition , function ( error , nextState ) {
404
- if ( error || nextState == null )
405
- return callback ( error , transition ) ;
383
+ if ( error || transition . isAborted || nextState == null )
384
+ return callback ( error , transition . abortReason ) ;
406
385
407
- self . setState ( nextState , function ( ) {
408
- callback ( null , transition ) ;
409
- } ) ;
410
- } ) ;
386
+ this . setState ( nextState , callback ) ;
387
+ } . bind ( this ) ) ;
411
388
} ,
412
389
413
390
/**
0 commit comments