I have a normal donejs model that reloads the same info every time I render a component for a new situation. The data changes rarely.
I cannot figure out how to make the model only load once and then let me render it repeatedly.
thanks,
tqii
I have a normal donejs model that reloads the same info every time I render a component for a new situation. The data changes rarely.
I cannot figure out how to make the model only load once and then let me render it repeatedly.
thanks,
tqii
If you can switch to can-connect, it solves this problem with the http://canjs.github.io/canjs/doc/can-connect/cache-requests/cache-requests.html cache-requests behavior.
If you can’t migrate, you can create a findAll
that saves the promise:
var findAllPromise;
can.Model.extend({
findAll: function(params){
if(findAllPromise)
return findAllPromise
return findAllPromise = $.get("/api/things", params);
}
},{})