ember-engines / ember-engines

Composable Ember applications for ambitious user experiences
http://ember-engines.com/
MIT License
490 stars 139 forks source link

Add transitionToExternal to router #260

Open mydea opened 7 years ago

mydea commented 7 years ago

I know that the '-routing' service is technically private, but we still use it every now and then, especially to transition from services. It would be nice to have the 'transitionToExternal' method available on the router, too, as a handy shortcut for:

export default Service.extend({
  routing: inject.service('-routing'),

  doSomething() {
    let router = get(this, 'routing.router');
    let externalRoute = getOwner(this)._getExternalRoute('my-external-route');
    router.transitionTo(externalRoute);
  }
});

Which I basically copied together from the route-ext.js file. Being able to do router.transitionToExternal('my-external-route') would be a nice simplification for this.

trentmwillis commented 7 years ago

This raises an interesting question, should each Engine have it's own Routing service? Currently, it seems like they do. If we intend to keep it that way then exposing a transitionToExternal method seems reasonable.

However, since routing is technically supposed to be handled by the root application, I wonder if we actually want each Engine to have a Routing service. I think it should be fine as the Routing service adds a layer of indirection to working with the Router, which means that we can give Engines access to routing while still making sure control is centralized.

Would like @rwjblue and @dgeb to chime in here before making a final decision. Also, if @ef4 has any thoughts on the matter.

ef4 commented 7 years ago

It's a good question. Certainly each engine needs to be able to interact with the routing service in the same way any application does (it should not require refactoring those interactions if you choose to make any example application into an engine).

What needs to be designed is how much isolation we want. For example, if somebody uses the routing service to install analytics, should those events fire for all transitions down inside child engines? What about the opposite case when the child does the registration? Also, the RouteInfo object describes the full route hierarchy today -- will it allow engines to peek downward and upward, or should we treat routes beyond the current engine as opaque and uninspectable?

jnfingerle commented 7 years ago

I would appreciate if transitionTo handled external Routes as well. I just stumbled over the problem, that a mixin has to be "engine aware" if it tries to transition to another route. If external Routes behaved like normal routes inside an engine, it would just work.

A longer discussion of this can be found at https://discuss.emberjs.com/t/how-do-i-find-out-if-im-inside-an-engine/12627/6

villander commented 4 years ago

transitory addon until #669 be merged - https://www.npmjs.com/package/ember-engines-router-service.