How to use the gun/gun.val 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 d3x0r / gun-db / testsetnul.js View on Github external
del = true;
else {
	console.log( "Must supply parameter 'add' or 'del'" );
	//process.exit(0);
}

var Gun = require( "gun/gun" );
var gunDb = require( "." );

//var Gun = require( "gun" );

require('gun/lib/not')
require( "gun-unset" );


const rel_ = Gun.val.rel._;  // '#'
const val_ = Gun._.field;  // '.'
const node_ = Gun.node._;  // '_'

var gun = new Gun( /*{ db:{ file:'gun.db' } }*/ );

console.log( new Date(), "Initialized gun instance" );
var root = gun.get( "db" );

var alice = root.get( "alice" )
alice.not( (val)=>{
	console.log( "init alice data", val );
	alice.put( { name: 'alice', dob: 'before now', whatever: 'one' } );
} );
var bob = root.get( "bob" )
bob.not( (val)=>{
	console.log( "init bob data" , val);
github d3x0r / gun-db / index.js View on Github external
//process.on( "warning", (warning)=>{console.trace( "WARNING:", warning ); } );
//process.on( "error", (warning)=>{console.trace( "ERROR PROCESS:", warning ); } );
//process.on( "exit", (warning)=>{console.trace( "EXIT:", warning ); } );

const Gun = require('gun/gun');
const vfs = require("sack.vfs");

var _debug_counter = 0;
var __debug_counter = 0;
var _debug_tick = Date.now();
const _debug = false;

const rel_ = Gun.val.rel._;  // '#'
const val_ = Gun.obj.has._;  // '.'
const node_ = Gun.node._;  // '_'
const state_ = Gun.state._;// '>';
const soul_ = Gun.node.soul._;// '#';

const ACK_ = '@';
const SEQ_ = '#';

Gun.on('opt', function(ctx){
	this.to.next(ctx);
	if(ctx.once){ return }
	var opt = ctx.opt.db || (ctx.opt.db = {});
	//opt.file = opt.file || ('file:gun.db?nolock=1');
	opt.file = opt.file || ('gun.db');
	var client = vfs.Sqlite(opt.file);
	var gun = ctx.gun;
github lmangani / gun-cassandra / index.js View on Github external
//process.on( "warning", (warning)=>{console.trace( "WARNING:", warning ); } );
//process.on( "error", (warning)=>{console.trace( "ERROR PROCESS:", warning ); } );
//process.on( "exit", (warning)=>{console.trace( "EXIT:", warning ); } );

const Gun = require('gun/gun');

var _debug_counter = 0;
var __debug_counter = 0;
var _debug_tick = Date.now();
const _debug = false;

const rel_ = Gun.val.rel._; // '#'
const val_ = Gun._.field; // '.'
const node_ = Gun.node._; // '_'
const state_ = Gun.state._; // '>';

var qb;

const ACK_ = '@';
const SEQ_ = '#';

Gun.on('opt', function(ctx) {

    var goNext = function(){
	    this.to.next(ctx);
	    if (ctx.once) {
	        return;
	    }
github SocialXNetwork / socialx_react_native / packages / api-data / src / extensions / docsubscribe.ts View on Github external
return this.on(function(data: any, key: string, ctx: any, ev: any){
		delete ((data = Gun.obj.copy(data))||{})._;
		clearTimeout(opt.to);
		opt.to = setTimeout(function(){
			if(!opt.any){ return }
			opt.any.call(opt.at.$, opt.doc, opt.key, opt, opt.ev);
			if(opt.off){
				opt.ev.off();
				opt.any = null;
			}
		}, 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];
github SocialXNetwork / socialx_react_native / packages / api-data / src / extensions / docload.ts View on Github external
return this.once(function(data, key, ctx, ev) {
		delete ((data = Gun.obj.copy(data)) || {})._;
		clearTimeout(opt.to);
		opt.to = setTimeout(function() {
			if (!opt.any) {
				return;
			}
			opt.any.call(opt.at, opt.doc, opt.key, opt, opt.ev);
			opt.ev.off();
			opt.any = null;
		}, opt.timeout || 600);
		opt.at = opt.at || ctx;
		opt.key = opt.key || key;
		// @ts-ignore-file
		opt.ev.s[this._.id] = ev;
		if (Gun.val.is(data)) {
			if (!at) {
				opt.doc = data;
			} else {
				at[key] = data;
			}
			return;
		}
		// @ts-ignore-file
		const tmp = this;
		let id;
		Gun.obj.map(data, function(val: any, key: string) {
			if (!(id = Gun.val.link.is(val))) {
				(at || opt.doc)[key] = val;
				return;
			}
			if (opt.ids[id]) {
github SocialXNetwork / socialx_react_native / packages / api-data / src / extensions / docload.ts View on Github external
Object.entries(o).map(([k, v]) => {
				const soul = Gun.val.rel.is(v);
				if (soul) {
					queue[soul] = true;
					root.get(soul).once((loadedValue: object) => {
						loadedValue = Gun.obj.copy(loadedValue);
						o[k] = loadedValue;
						queue[soul] = false;
						expand(loadedValue);
					}, {wait: 200});
					return;
				}

				// if it doesnt have a soul, just attach the value as is
				o[k] = v;
			});
github amark / gun / lib / time.js View on Github external
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;
github SocialXNetwork / socialx_react_native / packages / api-data / src / extensions / docsubscribe.ts View on Github external
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 gundb / sqlite / index.js View on Github external
function nodeify(record, node){
	if(!record){ return }
	var value;
	try{value = record.relation? Gun.val.rel.ify(record.relation) : JSON.parse(record.value);
	}catch(e){}
	return Gun.state.ify(node, record.field, parseFloat(record.state), value, record.soul);
}
github SocialXNetwork / socialx_react_native / packages / api-data / src / extensions / docload.ts View on Github external
Gun.obj.map(data, function(val: any, 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)
				.docOpen(opt.any, opt, (opt.ids[id] = (at || opt.doc)[key] = {}));
		});
	}, { wait: opt.wait || 300 });

gun

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

(Zlib OR MIT OR Apache-2.0)
Latest version published 20 days ago

Package Health Score

83 / 100
Full package analysis