Search code examples
ember.jsember-data

Ember model reloading in interval


I have a User model, which has latitude and longitude properties, which are used to show current user location on map.

App.User = DS.Model.extend({
    firstName: DS.attr('string'),
    lastName: DS.attr('string'),
    email: DS.attr('string'),
    jobs: DS.hasMany("App.Job"),
    latitude:   DS.attr('number'),
    longitude: DS.attr('number'),
    measuredAt: DS.attr('date'),
});

What is the best way to autoupdate latitude and longitude properties from server every given interval? Does ember-data support this kind of use case? I can't find any samples with this functionality. I think I will need to override find method for User class with setInterval in it, is this the right approach?

Thanks


Solution

  • For those who are coming across this question now -- don't use setInterval, it's been shown to cause serious memory leaks.

    Use Ember's own Ember.run.later instead.

    See also:

    Edit: Feb 3, 2019 - Update broken links.