#CafeMapper CafeMapper is/will-be a simple localStorge ORM at base. You can certainly try to use it now, but things will be rough. Watch the project though, very soon it'll be at a usable state.
- Thin object wrapper for localStorage
- Loose revision tracking for objects
- Sync via JSON to server datasource discretely or as a set.
- Feels comfortable with your server-side DataMapper.
- dominoes for Javascript loading/scheduling.
CafeMapper is being rewritten from existing (poorer) code. I'm by no means an expert, so feedback/corrections/issues are welcome.
Include cafemapper.js with dominoes (as shown in example.html) or just by using <script> tags.
To create a new Model, you simply:
var Person = $MODEL("Person");
You can also use the long, namespaced synax:
var Person = CafeMapper.Model.initAs("Person");
CafeMapper allows for (initially) basic client/server object synchronization. Before the final release, a hash of DataObject id's will be maintained so that the server can provide unprompted updates to the client. For now, you can have CafeMapper request an update after it is expired. CafeMapper will request a JSON serialized object from your server and then apply it to the local copy.
Person.include(CafeMapper.Modules.ServerCommunication);
This defines several feature and callback methods on Person such as Person#refresh, which triggers the server update flow.
CafeMapper lets you define stubs to populate empty/new objects with, rather than having to set it yourself. You could also define this type of behavior by creating your own CafeMapper.DataObject.initialize method and calling $super().
var Person = $MODEL("Person", {
initialize: function($super, data){
this.name = "John Smith";
this.zipcode = "20744";
}
});
Person.stub = {name: "John Smith" zipcode: 20744};