superfeedr / indexeddb-backbonejs-adapter

An indexedDB adapter for Backbonejs
http://blog.superfeedr.com/indexeddb-backbonejs-adapter/
MIT License
248 stars 61 forks source link

sync() should return a promise #23

Closed andornaut closed 11 years ago

andornaut commented 11 years ago

Backbone.indexdb.sync should maintain the same interface as Backbone.sync by returning a Deferred Promise object.

Backbone's sync() returns the xhr object from JQuery's ajax():

Backbone.sync = function(method, model, options) {
    //...

    var xhr = Backbone.ajax(_.extend(params, options));
    model.trigger('request', model, xhr, options);
    return xhr;
}
Backbone.ajax = function() {
    return Backbone.$.ajax.apply(Backbone.$, arguments);
};

This would also provide a workaround for people looking for synchronous behaviour such as in this other ticket #19.

Unfortunately Zepto doesn't provide an implementation of Deferred, but hopefully it'll be added soon:

https://github.com/madrobby/zepto/issues/353

julien51 commented 11 years ago

Please submit a patch. On Dec 16, 2012 1:06 PM, "andornaut" notifications@github.com wrote:

Backbone.indexdb.sync should maintain the same interface as Backbone.syncby returning a Deferred Promise object.

Backbone's sync() returns the xhr object from JQuery's ajax():

Backbone.sync = function(method, model, options) { //...

var xhr = Backbone.ajax(_.extend(params, options));
model.trigger('request', model, xhr, options);
return xhr;

}

Backbone.ajax = function() { return Backbone.$.ajax.apply(Backbone.$, arguments); };

This would also provide a workaround for people looking for synchronous behaviour such as in this other ticket #19https://github.com/superfeedr/indexeddb-backbonejs-adapter/issues/19 .

Unfortunately Zepto doesn't provide an implementation of Deferred, but hopefully it'll be added soon:

madrobby/zepto#353 https://github.com/madrobby/zepto/issues/353

— Reply to this email directly or view it on GitHubhttps://github.com/superfeedr/indexeddb-backbonejs-adapter/issues/23.

andornaut commented 11 years ago

Done #24