Route handling multiple complex components

For your use case, I think it makes sense to load data from the components, but I would suggest making the data loading functions into ember-concurrency tasks. Otherwise there are many concurrency bugs you’d have to solve manually. For example, the loading() method above:

  1. Is not cancelled if the component is torn down before the query finishes, which will result in an exception when set('isLoading', false) tries to run on a destroyed component.
  2. Allows multiple queries to race each other, if the input parameters change while a query is still running. The newest query doesn’t necessarily win, the fastest wins, and that could show inconsistent results.
  3. Gets stuck forever in the loading state if the query encounters a network error.

More detail on the general question of when and how to load data in the router vs components is here: This is relevant to your question:

Finally, I will point out that there’s no need to do this:

this.get('loading')(this)

You can invoke your own methods normally on Ember Component:

this.loading().

(Or use a Glimmer Component, which doesn’t extends from Ember.Object at all and has none of the special get, set, extend stuff that is causing this confusion.)

3 Likes