Calvin Flegal
Calvin Flegal

Reputation: 315

How to refresh Ember model and computed properties (AdapterPopulatedRecordArray)?

I'm having trouble getting a computed property to recompute.

My route looks like this:

App.DiagnosticsRoute = Ember.Route.extend({
  model: function() {
      return Ember.RSVP.hash({
          lights: this.store.find('light'),
          networkInterfaces: this.store.find('networkInterface'),
          networks: this.store.find('network', { diagnostics: "1"})
      });
  },
});

My controller has the following computed property:

  networksCount: function() {
    var networks_count = this.get('networks.length');
    if (0 == networks_count) return '(All Clear)';
    return networks_count;

  }.property('networks.length')

I'd like to poll the server to refresh the network collection. I've placed store.find('network') elsewhere in the App, and though the chrome ember extension shows the data is loaded into the store, the above computed property doesn't update. AdapterPopulatedRecordArray doesn't implement reload. How can I get the property to recompute??

Upvotes: 1

Views: 1288

Answers (1)

Calvin Flegal
Calvin Flegal

Reputation: 315

I found one pretty good solution via: How to update Ember's model periodically (such as in setInterval)?

  actions: {
    update: function() {
      this.set('networks',this.store.find('network'));
  }
  },
  networksCount: function() {
    var networks_count = this.get('networks.length');
    if (0 == networks_count) return '(All Clear)';
    return networks_count;

  }.property('networks.length')

Upvotes: 0

Related Questions