In my Ember app, I have a common mixin/code which has a transition call
myCommonFn: function() {
//this.transition('someRoute') // Works if context is route
//this.transitionTo('someRoute') // Works if context is controller
}
Now because this function is common across multiple routes, it can either be triggered from a controller or route
My question is how do I ensure this works in both the cases? Meaning should I add a check using
this.constuctor() //Check if it is controller or route
OR should I do a null/undefined check for
this.transition() OR this.transitionToRoute()
What is the best way to make it work in all cases ?
If your mixin is applied everywhere, the simplest is just to check and fire. Additionally, if you have plans to upgrade, eventually controllers are going away, so this may just be a temporary fix.
var transition = this.transitionTo || this.transitionToRoute;
transition.apply(this, [arg1, arg2,.....]);;
You also could also extend your common mixin two more times and have a base version, a controller version, and a route version where you could specify route/controller specific functionality.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.