Last active
August 10, 2016 21:21
-
-
Save justinbmeyer/52da6e176005cb1979607d0a95e8575c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var coolSocket = conenct.behavior("cool-socket", function(base){ | |
return { | |
init: function(){ | |
this.socket = something(); | |
this.socket.wasOffAndNowIsOn(function(){ | |
// get last date from localStorage | |
var lastDate = READ_FROM_LOCALSTORAGE; | |
this.socket.get(extend({},set, {since: lastDate})).then(function(newData){ | |
newData.data.forEach(this.createInstance) | |
}) | |
}) | |
}, | |
getListData: function(set){ | |
// | |
return this.cacheConnection.getListData(set).then(function(cachedData){ | |
var lastDate = READ_FROM_LOCALSTORAGE; | |
this.socket.ready.then(()=>{ | |
this.socket.get(extend({},set, {since: lastDate})).then(function(newData){ | |
return {data: cacheData.data.concat(newData.data)} | |
}) | |
}) | |
}) | |
} | |
} | |
}); | |
connect([ | |
require("can-connect/constructor/"), | |
require("can-connect/constructor/store/"), | |
... // all other behaviors here | |
coolSocket | |
],{ | |
algebra: ..., | |
Map: Todo, | |
... | |
}) | |
Todo.getList({}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment