Costa
Costa

Reputation: 654

Ember.js update models from application controller

I need to update data every minute and on some specific events.

My idea is to create an action in ApplicationRoute, that would find the current router and evoke the model() method again.

But how can I access other routes from ApplicationRoute?
Maybe there are any other ideas to make it?

Upvotes: 2

Views: 72

Answers (1)

You don't have to reenvoke the model hook.

The matter is that most store data retrieval methods, for example, store.findAll() (ex store.find()) return live arrays. A live array will automatically update its content whenever new records appear in the store or existing records are removed.

So all you need is to repopulate the store.

A good place to periodically fetch the data is a service.

Also, you can enable/disable periodic data retrieval from within routes. Simply create a mixin that would enable data retrieval in the service when the route is visited and disable when the route is left.

Upvotes: 1

Related Questions