Last active
December 26, 2015 02:09
-
-
Save kennethdavidbuck/7075898 to your computer and use it in GitHub Desktop.
An attempt to return to the last route visited within a given resouce.
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
/** | |
* | |
*/ | |
Em.RememberRouteMixin = Em.Mixin.create({ | |
/** | |
* Whether or not this route should catch | |
* bubbling transitions and use them as a default | |
* transition object. | |
*/ | |
catchTransition:false, | |
/** | |
* Default route path to when there is no | |
* lastTransition object | |
*/ | |
defaultRoute:null, | |
/** | |
* Transition object to use in order to | |
* return to the last route visited for the | |
* current resource | |
*/ | |
lastTransition:null, | |
/** | |
* | |
*/ | |
redirect:function(){ | |
"use strict"; | |
if(this.get('catchTransition')) { | |
var lastTransition = this.get('lastTransition'), | |
defaultRoute = this.get('defaultRoute'); | |
if(!Em.isEmpty(lastTransition)) { | |
lastTransition.retry(); | |
} else if(!Em.isEmpty(defaultRoute)) { | |
this.transitionTo(defaultRoute); | |
} | |
} | |
}, | |
/** | |
* Wait a moment, then attempt to bubble transition to | |
* parent an expectant parent route. | |
*/ | |
afterModel:function(model,transition){ | |
"use strict"; | |
this._super(); | |
if(!this.get('catchTransition')) { | |
Em.run.next(this,function(){ | |
this.send('setLastTransition',transition); | |
}); | |
} | |
}, | |
/** | |
* | |
*/ | |
actions:{ | |
/** | |
* | |
*/ | |
setLastTransition:function(transition){ | |
"use strict"; | |
if(this.get('catchTransition')) { | |
this.set('lastTransition',transition); | |
return false; | |
} | |
return true; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment