Wednesday, September 24th, 2008

OfflineRest: One pattern for offline architecture

Category: Dojo, Offline

<>p>

Kris Zyp has created OfflineRest, a new module in Dojo 1.2 that allows for a simple offline pattern to building your application.

Dojo 1.2’s new dojox.rpc.OfflineRest module automates the local storage of data and synchronization by leveraging the Dojo Data and REST abstractions. The OfflineRest module augments the JsonRest service in Dojo such that requests are cached in local storage for offline access, and modification requests (put, post, and delete) modify the cache and are recorded for delivery to the server; immediately if online, otherwise when connectivity is restored. Furthermore, JsonRest is the core engine used by JsonRestStore. Consequently, you can simply use the standard Dojo Data API with the JsonRestStore and effortlessly add offline capability with no modifications to your data interaction code. The underlying Rest service automates the handling of caching, storing data locally, and syncing changes. In addition the new OfflineRest module has no dependency on plugins, but rather progressively utilizes offline features that are available, while still operating properly on legacy browsers without offline support.

He has a demo that involves a CRUD system for hiking trails which interestingly asked me for Gears permission, even though it appears that OfflineRest doesn’t abstract on top of both Gears and the emerging storage standard, which is something I would like to see, to extend the reach.

javascript
< view plain text >
  1. dojo.require("dojox.rpc.OfflineRest");
  2. dojo.require("dojox.data.JsonRestStore");
  3.  
  4. // create a store
  5. trailStore = new dojox.data.JsonRestStore({url:"/Trail"});
  6. dojox.rpc.OfflineRest.addStore(trailStore,"");
  7.  
  8. // data
  9. var item = trailStore.newItem();
  10. trailStore.setValue(item,"foo","bar");
  11.  
  12. // manually observing download changes to force updates
  13. dojo.connect(dojox.rpc.OfflineRest, "downloadChanges", function(){
  14.     .. download changes or refresh the page ..
  15. });

Related Content:

Posted by Dion Almaer at 6:19 am
1 Comment

+++--
3.7 rating from 37 votes

1 Comment »

Comments feed TrackBack URI

@Dion: OfflineRest will ask for permission to use Gears if you have Gears installed. Otherwise it will look to HTML5 storage, and then to utilize Flash as last resort (this is Dojo’s standard local storage strategy).

Comment by kriszyp — September 24, 2008

Leave a comment

You must be logged in to post a comment.