You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Load a list of names with progressive enhancement. The list will be populated
from cache on refresh, and new items will pop up when server responds to fetch.
varuserCollection=require('usercollection');varusers=userCollection.fetch('active');users.each(show);// Show cached resultsusers.on('change',function(){this.each(show);// Show server results});varbody=document.body;vardomNodes={};vartpl='<p data-text="name"></p>';functionshow(model){varnode=domNodes[model.id()]||reactive(domify(tpl),model);body.appendChild(node.el);};
API
This plugin introduces the methods
fetch(url, fn)
Fetch the models at model.url() or at options.url, returning a new collection
instance with the result. Caches the response as a list of ids.
varcacheCollection=collection.fetch('/users/active',function(err,updated){// updated is the same collection after it has been fetched});// cacheCollection is a cached version of the model, or just an empty model with the id
get(id, fn)
Fetch the model by id, returns model instance and updates it async. Use fn to
wait for server, or no callback to use cached.
varcached=collection.get('id',function(err,updated){// updated is a reference to model after it has been updated});// cached is a cached version of the model, or just an empty model with the id