mardi 17 novembre 2015

Ember promise isPending not firing if thenable

I want to show a loading spinner in an ember component when I load some data from the store. If there is an error from the store, I want to handle it appropriately.

Here is a snippet of my current code:

cachedCampaignDataIsPending: computed.readOnly('fetchCachedCampaignData.isPending'),

fetchCachedCampaignData: computed('campaign', function() {
  return this.get('store').findRecord('cachedCampaignMetric').then( (cachedMetrics) => {
    this.set('cachedCampaignData', cachedMetrics);
  }, () => {
    this.set('errors', true);
  });
}),

This will properly set the errors to true if the server responds with an error, however, the cachedCampaignDataIsPending is not acting properly. It does not get set to true.

However, if I rewrite my code to make the computed property not be thenable, then it does fire propertly.

fetchCachedCampaignData: computed('campaign', function() {
  return this.get('store').findRecord('cachedCampaignMetric');
}),

Anyone know the reason why, or how to make it fire properly, using the then/catch logic?

Thanks.

Aucun commentaire:

Enregistrer un commentaire