Uses localstorage db in offline mode

This commit is contained in:
2016-01-29 22:51:59 +08:00
parent 39d4284de3
commit f0cf9e6d7b
6 changed files with 180 additions and 33 deletions
+14 -3
View File
@@ -2,19 +2,30 @@ define(
[
'backbone',
'models/task',
'localstorage',
'localforage',
'localforagebackbone'
],
function(
Backbone,
Task,
LocalStorage
localforage,
localforageBackbone
) {
var List = Backbone.Collection.extend({
localStorage: new Backbone.LocalStorage("tasks"),
model: Task,
offlineSync: Backbone.localforage.sync("tasks"),
/** switches sync between server and local databases **/
sync: function(){
if (window.hackflowyOffline)
return this.offlineSync.apply(this, arguments);
else
return Backbone.sync.apply(this, arguments);
},
url: '/tasks'
});