This private API is one I use frequently in my applications to programmatically get the current route's model. It is mostly a convenience for this.modelFor(this.routeName)
¹. This is especially useful for writing re-usable route code which needs to get at the current route's model.
¹ Though routeName
is private, see #11759
:+1: super useful - when I see in a route this.modelFor('a.route.name')
I always have to double-check to see if it's the current route's name or not. This would eliminate that source of confusion, especially it seems the best practice is to have the route handle actions by manipulating its own model, and (ideally) not some other route's model.
Discussed this at the core team meeting this afternoon, and decided that we'd like to keep this as private. As you mentioned this.modelFor(this.routeName)
(I just chimed in on #11759 that we should make this.routeName
public) is a good way to do this with public API's. You can also use this.get('controller.model')
. Both of these suggestions shoudl remove the ambiguity with this.modelFor('a.b.c')
that @davidgoli mentioned..
Thanks for opening the issue for discussion, I'm going to close now that we have discussed and decided to keep private.
Sounds good, I will then create an alias in ApplicationRoute
that's just currentModel: function () { return this.modelFor(this.routeName); }
because that is immensely useful and a shame it's getting overlooked. But we shall carry on!
Most helpful comment
Sounds good, I will then create an alias in
ApplicationRoute
that's justcurrentModel: function () { return this.modelFor(this.routeName); }
because that is immensely useful and a shame it's getting overlooked. But we shall carry on!