Hey. Thanks for backbone-pouch, everything is very smooth so far :)
I'm porting an application that saves the models on a remote server via Backbone's XHR to PouchDB and backbone-pouchdb. In the current version, save() sends the complete JSON representation to the server and retrieves a complete JSON representation back from the server (I guess that's custom to my application, but I believe that is a nice REST architecture and allows the server to also change the document).
So, in Model.parse, my code (quoting http://backbonejs.org/#changelog 's 1.1.0 section here)
"extract[s] and vivify[s] incoming nested JSON into associated submodels. "
With backbone-pouchdb, however, the data argument for parse is always an object containing just _id and _rev, without the attributes that have just been saved, because of these lines:
response = {
_id: response.id,
_rev: response.rev
};
I'd propose to respond with this instead:
response = extend({}, model.toJSON(), {
_id: response.id,
_rev: response.rev
});
so the model doesn't think the the server (or PouchDB in this case) deleted all the attributes.
Also, one could argue to only call model.toJSON() once, but I wanted to discuss in general this first before making optimizations.
Hey. Thanks for backbone-pouch, everything is very smooth so far :)
I'm porting an application that saves the models on a remote server via Backbone's XHR to PouchDB and backbone-pouchdb. In the current version, save() sends the complete JSON representation to the server and retrieves a complete JSON representation back from the server (I guess that's custom to my application, but I believe that is a nice REST architecture and allows the server to also change the document).
So, in
Model.parse, my code (quoting http://backbonejs.org/#changelog 's 1.1.0 section here)With backbone-pouchdb, however, the
dataargument forparseis always an object containing just_idand_rev, without the attributes that have just been saved, because of these lines:I'd propose to respond with this instead:
so the model doesn't think the the server (or PouchDB in this case) deleted all the attributes.
Also, one could argue to only call
model.toJSON()once, but I wanted to discuss in general this first before making optimizations.