I have a search results page, which is developed using EmberJS. I use Ember.Route to load data through from API. The search API which i was using is very slow. So we decided to load the data from a cache API. But the problem is that, the cache might have some old data. So we decided to re-load data in the already loaded page using search API.
My existing Route code would look like this
define(‘search’, ['jquery'], function($) {
var route = Ember.Route.extend({
model: function() {
return searchApiCall( someParameter );
},
setupController: function(controller, model) {
controller.set('model', model);
}
});
return route;
});
In the above code, am just calling the search API and returning the json response. But, what i want is something as below.
define(‘search’, ['jquery'], function($) {
var route = Ember.Route.extend({
model: function() {
setTimeout(function(){
return searchApiCall( someParameter );
}, 10);
return cachedSearchResult( someParameter );
},
setupController: function(controller, model) {
controller.set('model', model);
}
});
return route;
});
So what am looking in the above code is to pass the cached result at first and then somehow load the result from actual search api when its available.
Please let me know, whats the best way for this in EmberJS.
Aucun commentaire:
Enregistrer un commentaire