database - Getting streaming data from gun -
on() supposed stream data path or key 1. when put data on path, i'm not seeing updated stream.
var mydata = gun('https://gunjs.herokuapp.com/gun') .get('example/demo/set'); mydata.on(); mydata.put({hello:'world'});
.on() asynchronous function, need update code this:
var mydata = gun('https://gunjs.herokuapp.com/gun') .get('example/demo/set'); mydata.on(function(data){ console.log("update:", data); }); mydata.put({hello:'world'}); hope helps!
if new programming, "anonymous functions" (often times called callback) in above code can confusing. above code can rewritten this, has exact same behavior:
var mydata = gun('https://gunjs.herokuapp.com/gun') .get('example/demo/set'); var cb = function(data){ console.log("update:", data); }; mydata.on(cb); mydata.put({hello:'world'}); for debugging purposes, there .val() convenience function automatically log data you:
var mydata = gun('https://gunjs.herokuapp.com/gun') .get('example/demo/set'); mydata.on().val() mydata.put({hello:'world'}); however intended one off purposes, not streaming. note, can pass .val(function(data){}) callback override default convenience logger.
Comments
Post a Comment