+34
-28
| 'use strict' | ||
| class Firearm { | ||
| constructor(gun, opts) { | ||
| constructor({gun, Gun, opts}) { | ||
| this.gun = gun | ||
| this.Gun = (typeof window !== 'undefined') ? window.Gun : require('gun/gun') | ||
| // If we don't pass gun instance, then see if it's available from window or file - use Firearm's args to create a new gun instance. | ||
| /*const hasGun = (gun && gun.chain) ? true : false | ||
| if (!hasGun) | ||
| this.gun = this.Gun(...arguments) | ||
| */ | ||
| this._ctx = null | ||
| this._ctxVal = null | ||
| this._ready = true | ||
| this._proxyEnable = true | ||
| // Immutability is an opt-in feature. use: new Firearm(gun, { immutable: true }) | ||
| this.immutable = (opts && opts.immutable) ? true : false | ||
| const that = this | ||
| this.Gun.on('opt', function(context) { | ||
| that._registerContext = context | ||
| this.to.next(context) | ||
| }) | ||
| this.gun = this.Gun(...arguments) | ||
| this.mutate = this.mutate.bind(this) | ||
| this.extend = this.extend.bind(this) | ||
| return new Proxy(this.gun, firearmProxy(this)) | ||
| this.Gun = (typeof window !== 'undefined') ? window.Gun : Gun | ||
| if(!Gun){ | ||
| let err = { | ||
| err: 'no gun class supplied' | ||
| } | ||
| return err | ||
| } else { | ||
| // If we don't pass gun instance, then see if it's available from window or file - use Firearm's args to create a new gun instance. | ||
| /*const hasGun = (gun && gun.chain) ? true : false | ||
| if (!hasGun) | ||
| this.gun = this.Gun(...arguments) | ||
| */ | ||
| this._ctx = null | ||
| this._ctxVal = null | ||
| this._ready = true | ||
| this._proxyEnable = true | ||
| // Immutability is an opt-in feature. use: new Firearm(gun, { immutable: true }) | ||
| this.immutable = (opts && opts.immutable) ? true : false | ||
| const that = this | ||
| this.Gun.on('opt', function(context) { | ||
| that._registerContext = context | ||
| this.to.next(context) | ||
| }) | ||
| this.gun = this.Gun(...arguments) | ||
| this.mutate = this.mutate.bind(this) | ||
| this.extend = this.extend.bind(this) | ||
| return new Proxy(this.gun, firearmProxy(this)) | ||
| } | ||
| } | ||
@@ -34,0 +40,0 @@ |
+1
-1
| { | ||
| "name": "firearm", | ||
| "version": "0.0.1", | ||
| "version": "0.0.11", | ||
| "description": "Wrapper around [GunDB](https://github.com/amark/gun) to provide alternative syntax, promise support, utility modules, and easy Gun adapter events.", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
13273
0.51%166
4.4%