Search code examples
ember.jsember-dataember-cli

How to use ember-cli-clock to reload the route's model?


I'm using ember-cli-clock which lets me do this in a controller:

  date: function () {
    return moment().format('dddd MMMM Do');
  }.property('clock.minute'),

This is really neat and as you can guess, live updates dates and times on a particular time interval.

How do I use this in order to reload the model for a route when the date changes (or anything else for that matter)?

The model does have a reload method, I'm just not sure how to hook into it from the clock event?


Solution

  • You can use an observer in your controller:

    date: function() {
        return moment().format('dddd MMMM Do');
    }.property('clock.minute'),
    
    refreshModel: function() {
        // You can also do some logic here to conditionally
        // reload the model when the clock is in a certain state
        this.get('model').reload();
    }.observes('clock.minute')