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()

getter = query => {
  query.split(".").reduce((db,val) => {
    return db.get(val)
  }, gun).val((data) => {
    console.log(query, data)
  })
}
setter = (query,valueToSet) => {
  if (getter(query) ) { // getter(query) !== val maybe JSON.stringify()
    // add to postList
    console.log(query, valueToSet)
    query.split(".").reduce((db,val) => {
      return db.get(val)
    }, gun).put(valueToSet)
  }
}

setter('marcus',{
  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!
setter('marcus', marcus)
setter('marcus.is',"making a cache")

getter("marcus.boss")
getter("marcus.boss.slave.boss.is")
getter("marcus.boss.slave.is")
Clone this wiki locally