Fix for offline sync

This commit is contained in:
2016-01-30 07:26:13 +08:00
parent f0cf9e6d7b
commit ed4641650b
2 changed files with 61 additions and 44 deletions
+17 -9
View File
@@ -13,22 +13,30 @@ localforage,
localforageBackbone
) {
var List = Backbone.Collection.extend({
var List = Backbone.Collection.extend({
model: Task,
offlineSync: Backbone.localforage.sync("tasks"),
/** switches sync between server and local databases **/
sync: function(){
model: Task,
offlineSync: Backbone.localforage.sync("tasks"),
/** switches sync between server and local databases **/
sync: function(){
//var self = this;
_localforageNamespace = this.offlineSync._localforageNamespace;
_localeForageKeyFn=this.offlineSync._localeForageKeyFn;
localforageKey = this.offlineSync._localeForageKeyFn;
if (window.hackflowyOffline)
return this.offlineSync.apply(this, arguments);
else
return Backbone.sync.apply(this, arguments);
},
},
url: '/tasks'
url: '/tasks'
});
});
// a couple of vars backbone.localforage needs in the sync function
List.prototype.sync.localforage = List.prototype.offlineSync._localeForageKeyFn;
List.prototype.sync._localeForageKeyFn = List.prototype.offlineSync._localeForageKeyFn;
List.prototype.sync._localforageNamespace = List.prototype.offlineSync._localforageNamespace;
return List;