How to use the gun/gun.state function in gun

To help you get started, we’ve selected a few gun examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github amark / gun / lib / time.js View on Github external
return travel(data, a, b, this);
		}
		var gun = this, root = gun.back(-1);
		var cb = (a instanceof Function && a) || (b instanceof Function && b);
		if(Gun.is(data)){
			data.get(function(soul){
				if(!soul){
					return cb && cb({err: "Timegraph cannot link `undefined`!"});
				}
				gun.time(Gun.val.link.ify(soul), a, b);
			}, true);
			return gun;
		}
		opt = (cb === a)? b : a;
		opt = Gun.text.is(opt)? {key: opt} : opt || {};
		var t = new Date(Gun.state()).toISOString().split(/[\-t\:\.z]/ig);
		var p, tmp = t.pop();
		gun.get(function(soul){
			var id = soul;
			p = id;
			if(!p){ id = p = (gun.back('opt.uuid') || Gun.text.random)(9) }
			// could shrink this into a loop. Do later?
			t = [p].concat(t);
			var rid = opt.key || (gun.back('opt.uuid') || Gun.text.random)(9);
			var milli = ify({}, t.join(':'));
			milli[rid] = data;
			tmp = t.pop();
			var sec = ify({}, t.join(':'));
			sec[tmp] = milli;
			tmp = t.pop();
			var min = ify({}, t.join(':'));
			min[tmp] = sec;
github sjones6 / gun-flint / src / Adapter / index.js View on Github external
const union = function union(vertex, node, opt){
	if(!node || !node._){ return }
	vertex = vertex || Gun.state.to(node);
	if(!vertex || !vertex._){ return }
	opt = Gun.num.is(opt)? {machine: opt} : {machine: Gun.state()};
	opt.union = Gun.obj.copy(vertex); // Slow performance.
	if(!Gun.node.is(node, function(val, key){
		var HAM = Gun.HAM(opt.machine, Gun.state.is(node, key), Gun.state.is(vertex, key, true), val, vertex[key]);
		if(!HAM.incoming){ return }
		Gun.state.to(node, key, opt.union);
	})){ return }
	return opt.union;
}
/* eslint-enable */
github amark / gun / lib / time.js View on Github external
function now(t){
		return new Date(t || Gun.state()).toISOString().split(/[\-t\:\.z]/ig).slice(0,-1);
	}
	function find(o, cb, root, at, off){

gun

A realtime, decentralized, offline-first, graph data synchronization engine.

(Zlib OR MIT OR Apache-2.0)
Latest version published 1 year ago

Package Health Score

64 / 100
Full package analysis