I am studying Ember.js and writing an application that I want to perform the following tasks ...
- Download some data from local storage.
- check third-party API for new additional data
- add more and save everything in local storage
- display a table of this data
My application is just one route. I am using the Ember.Route model hook to load data from local storage. Where is a good place to check if there is a third-party API for any new data? Should I also do this in a model hook? I would like to be able to display some kind of loading icon during the request for a third-party API, and I'm not sure if this model hook will allow me to do this?
Right now, my Route contains only the following code ...
App.HistoryRoute = Ember.Route.extend({ model: function (params) { // initialize model var model = { summoner: params, history: [] }; if (typeof(localStorage.history) == 'undefined') return model; // fetch the data from local storage var history = JSON.parse(localStorage.history); // check for existing data if (!history.hasOwnKey(params.region) || !history[params.region].hasOwnKey(params.name)) return model; // use the data from local storage return history[params.region][params.name]; } });
Data in local storage is named using the realm and name. It looks something like this ...
{ "NorthAmerica": { "ryan": { "summoner": { "region": "NorthAmerica", "name": "ryan" }, "history": [ ... ] } } }
Thus, the Route model method loads this data so that it can be used as a model. Where should I hit a third-party API to get new data? I would like to check it for new data every time the page is refreshed. Thanks!
source share