-
Notifications
You must be signed in to change notification settings - Fork 5
Home
Marcus Hitchins edited this page Mar 28, 2018
·
10 revisions
Thoughts: get
- check gundb
- Fire API calls for all missing data
- Put all returned data into gundb
- return relevant data
set
- check gundb if diff
- set gundb
- add to postList
- onIdle(5000,1000).then(APIsync(postList))
function onIdle (itime, failAfter) {
return new Promise(function (resolve, reject) {
var trys = 0
var onIdleTest = function() {
var t = performance.now()
setTimeout(function(){
if (failAfter && trys++ > failAfter) {
reject()
}
if (Math.round(performance.now() - t) === Math.round(itime)) {
resolve()
} else {
onIdleTest()
}
}, itime)
}
onIdleTest()
})
}
onIdle(5000,1000).then(APIsync)
var gun = Gun()
gun.get('marcus').put({
name: "Marcus",
email: "[email protected]",
})
var russell = {name: "Russell", is: "full stack butterfly"}
var marcus = {boss: russell}
russell.slave = marcus
// partial updates merge with existing data!
gun.get('marcus').put(marcus)
getter = query => {
query.split(".").reduce((db,val) => {
return db.get(val)
}, gun).val((data) => {
console.log(query, data)
})
}
getter("marcus.boss.slave.boss")
getter("marcus.boss.slave.boss.is")