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
{{ message }}
This repository was archived by the owner on Nov 27, 2018. It is now read-only.
Jason Mulligan edited this page Feb 2, 2013
·
10 revisions
Creating a RESTful data store
Please read Creating a data store before continuing.
A RESTful data store abstracts API interaction automatically for you "behind the scene". Being RESTful implies being part of the feedback loop, so if you create, update or delete a record it will be reconciled with the Server before the local representation reflects the change.
The API end point under a collection will become the key of the local record, e.g. http://api.yourdomain.com/users/123 is record 123; the users collection would be a child data store , accessible via app.data.get("users");
Recursive API crawling can be initiated by setting data.retrieve & data.recursive to true.
When you make a data store RESTful, you can explicitly expire the data via data.setExpires.
You can "ping" a data store to see if it's "ready" by checking the data.loaded boolean.
varapp=$.data({id: "app"},null,{key: "name"}),uri="http://api.yourdomain.com";// Removing the `afterDataSet` listener while data streams inuri.on("beforeExpires",function(){app.un("afterDataSet","update");});app.data.setUri(uri).then(function(recs){// Data is loaded…// Setting update listener for User interaction, etc.app.on("afterDataSet",function(arg){…},"update");},function(e){// Something went wrong…});app.data.setExpires(5*60*1000);// data is valid for 5 minutes