Skip to content
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('mark').put({
  name: "Mark",
  email: "[email protected]",
});
var cat = {name: "Fluffy", species: "kitty"}
var mark = {boss: cat}
cat.slave = mark

// partial updates merge with existing data!
gun.get('mark').put(mark)
query = "mark.boss.slave.boss.slave"

query.split(".").reduce((db,val) => {
  return db.get(val)
}, gun).val(function(data){
  console.log(query, data);
})
Clone this wiki locally