How to use the gun/gun.obj 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 SocialXNetwork / socialx_react_native / packages / api-data / src / extensions / docload.ts View on Github external
return this.once((obj: object = {}, key: string) => {
		// if null or undefined (but shouldnt be able to be that, right ?).. skip it if opt allows
		if (obj === null) {
			return;
		}

		const { _: obSoul, ...obRest } = Gun.obj.copy(obj);
		obj = obRest;

		// next objects to dig into
		const queue: any = {};
		// current doc (passed on the callback)
		let doc: object;
		// flag
		let done: boolean;

		// get deeper into the reference soul
		const expand = (newObj: object | any = {}) => {
			const { _: newObSoul, ...o } = newObj;
			// console.log("que", queue);
			// if doc is null assign the current object to the doc
			if (!doc) {
				doc = o;
github PsychoLlama / Trace / web / find.js View on Github external
module.exports = function find(player) {
	var coord, position;
	coord = sort(player);
	coord = coord[coord.length - 1];

	// if the player has no history
	if (!coord) {
		return null;
	}

	// don't mutate the last position, make a copy
	position = Gun.obj.copy(coord);

	position[coord.axis] = distance(coord);
	position.time = Gun.time.is();

	return position;
};
github PsychoLlama / Trace / web / collision.js View on Github external
function collision() {
	var lines = [];

	// add every player's history to the list of lines
	Gun.obj.map(players.list, function (player, number) {
		var history = path(player);
		lines = lines.concat(history);
	});

	/*
		Filter out lines that aren't dangerous,
		then filter out the ones that aren't in
		your way, then filter out the ones you're
		not overlapping with.
	*/
	return lines.filter(function (line) {
		return line.axis !== position.axis;
	}).filter(inPath).filter(crossing).length;
}
github SocialXNetwork / socialx_react_native / packages / api-data / src / extensions / docsubscribe.ts View on Github external
}, opt.wait || 1);
		opt.at = opt.at || ctx;
		opt.key = opt.key || key;
		// @ts-ignore
		opt.ev.s[this._.id] = ev;
		if(Gun.val.is(data)){
			if(!at){
				opt.doc = data;
			} else {
				at[key] = data;
			}
			return;
		}
		// @ts-ignore
		var tmp = this, id;
		Gun.obj.map(data, function(val: object, key: string){
			if(!(id = Gun.val.link.is(val))){
				(at || opt.doc)[key] = val;
				return;
			}
			if(opt.ids[id]){
				(at || opt.doc)[key] = opt.ids[id];
				return;
			}
			tmp.get(key).docSubscribe(opt.any, opt, opt.ids[id] = (at || opt.doc)[key] = {});
		});
	})
}
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 PsychoLlama / Trace / server / game / expire.js View on Github external
setInterval(function () {
	Gun.obj.map(game.players, function (player, number) {
		if (!player) {
			return;
		}
		if (expired(player)) {
			console.log('Kicking player', number);
			game.db.path(number).put(null);
		}
	});
}, 1000);
github SocialXNetwork / socialx_react_native / packages / api-data / src / extensions / docsubscribe.ts View on Github external
opt.ev = opt.ev || {off: function(){
		Gun.obj.map(opt.ev.s, function(e: any){
			if(e){ e.off() }
		});
		opt.ev.s = {};
	}, s:{}}
	return this.on(function(data: any, key: string, ctx: any, ev: any){
github gundb / sqlite / index.js View on Github external
store.Record.upsert(id, data).then(function(){
				Gun.obj.del(block, id);
				Gun.obj.del(block, soul);
				check[id] = false;
				if(Gun.obj.map(check, function(val){
					if(val){ return true }
				})){ return }
				gun.on('in', {'@': at['#'], ok: 1});
			}, function(e){
				if(e && e.toString().indexOf('UNIQUE') >= 0){
github SocialXNetwork / socialx_react_native / packages / api-data / src / extensions / docload.ts View on Github external
root.get(soul).once((loadedValue: object) => {
						loadedValue = Gun.obj.copy(loadedValue);
						o[k] = loadedValue;
						queue[soul] = false;
						expand(loadedValue);
					}, {wait: 200});
					return;
github gundb / sqlite / index.js View on Github external
store.Record.upsert(id, data).then(function(){
				Gun.obj.del(block, id);
				Gun.obj.del(block, soul);
				check[id] = false;
				if(Gun.obj.map(check, function(val){
					if(val){ return true }
				})){ return }
				gun.on('in', {'@': at['#'], ok: 1});
			}, function(e){
				if(e && e.toString().indexOf('UNIQUE') >= 0){

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