New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bkb

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bkb - npm Package Compare versions

Comparing version 0.17.3 to 0.17.4

2

bkb.d.ts

@@ -120,3 +120,3 @@ declare function createApplication<A>(Cl: { new (dash: ApplicationDash<A>, ...args: any[]): A }, ...args: any[]): Application<A>

*/
emit(eventName: string, data?: any, options?: EmitterOptions): this
emit(eventName: string | string[], data?: any, options?: EmitterOptions): this

@@ -123,0 +123,0 @@ /**

@@ -1,1 +0,1 @@

"use strict";function createApplication(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=new ApplicationContainer(t,!1,e);return r.root.getInstance()}function toApplication(t){var e=new ApplicationContainer(t,!0);return e.root.dash}function makeBkb(t,e){var n={get instance(){return t.getInstance()},get parent(){return this.getParent()},getParent:function(e){var n=t.getParent(e);return n?n.getInstance():void 0},on:function(e,n,r,o){return t.emitter.listen(e).call(n,r,o),this},listen:function(e){return t.emitter.listen(e)},destroy:function(){return t.destroy()},componentName:t.componentName,componentId:t.componentId,find:function(e){return void 0===e&&(e={}),t.find(e)},findSingle:function(e){return void 0===e&&(e={}),t.findSingle(e)},count:function(e){return void 0===e&&(e={}),t.count(e)},has:function(e){return void 0===e&&(e={}),t.has(e)}};return e&&Object.assign(n,e),Object.freeze(n),n}function makeDash(t,e){var n=Object.assign(Object.create(e),{setInstance:function(e){return t.setInstance(e)},exposeEvents:function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=1===e.length&&Array.isArray(e[0])?e[0]:e;return t.emitter.exposeEvents(r,!0),this},create:function(e,n){return void 0===n&&(n={}),t.createComponent(e,n,!1).getInstance()},toComponent:function(e,n){return void 0===n&&(n={}),t.createComponent(e,n,!0).dash},emit:function(e,n,r){return t.emit(e,n,r),this},broadcast:function(e,n){return t.broadcast(e,n),this},listenToParent:function(e,n){return void 0===n&&(n={}),t.listenToParent(e,n)},listenToChildren:function(e,n){return t.childEmitter.listen(e,n)},listenTo:function(e,n){return t.listenTo(e,n)},bkb:e});return t.app.root&&t.app.root!==t&&Object.defineProperty(n,"app",{get:function(){return t.app.root.getInstance()}}),Object.freeze(n),n}function call(t,e){switch(t.mode){case"dataFirst":t.thisArg?t.callback.call(t.thisArg,e.data,e):t.callback(e.data,e);break;case"arguments":t.thisArg?t.callback.apply(t.thisArg,e.data):t.callback.apply(t,e.data);break;case"eventOnly":default:t.thisArg?t.callback.call(t.thisArg,e):t.callback(e)}}exports.createApplication=createApplication,exports.toApplication=toApplication;var ApplicationContainer=function(){function t(t,e,n){var r=this;this.compCount=0,this.nodes=new Map,this.tickList=null,this.insideRmComp=!1;var o=["error","warn","info","debug","trace"],i=this.newId();this.root=new Container(this,"root",i,{nextTick:function(t){return r.nextTick(t)},log:this.createLog(o)}),this.nodes.set(i,{container:this.root}),this.root.emitter.exposeEvents(["log"].concat(o,["addComponent","removeComponent","changeComponent"]),!1),e?this.root.setInstance(t):this.root.makeInstance(t,n||[])}return t.prototype.getParentOf=function(t){var e=this.findNode(t);return e.parent?e.parent.container:void 0},t.prototype.getChildrenOf=function(t){var e=[],n=this.findNode(t).children;if(n)for(var r=0,o=Array.from(n.values());r<o.length;r++){var i=o[r];e.push(i.container)}return e},t.prototype.getContainer=function(t){return this.findNode(t).container},t.prototype.createComponent=function(e,n,r,o){if(!this.root.dash)throw new Error("Destroyed root component");var i=o.componentName||t.getComponentName(e),s=this.newId(),a=new Container(this,i,s),c=this.findNode(n.componentId),h={container:a,parent:c};return this.nodes.set(s,h),c.children||(c.children=new Map),c.children.set(s,h),r?a.setInstance(e):a.makeInstance(e,o.args||[]),this.root.dash.emit("addComponent",{component:a.getInstance()}),this.root.dash.emit("changeComponent",{component:a.getInstance(),type:"add"}),a},t.prototype.removeComponent=function(t){if(!this.root.dash)throw new Error("Destroyed root component");var e=!this.insideRmComp;try{e&&(this.insideRmComp=!0,this.root.dash.emit("removeComponent",{component:t.getInstance()},{sync:!0}),this.root.dash.emit("changeComponent",{component:t.getInstance(),type:"remove"},{sync:!0}));var n=t.componentId,r=this.findNode(n);if(r.children){for(var o=0,i=Array.from(r.children.values());o<i.length;o++){var s=i[o];s.parent=null,s.container.destroy()}r.children.clear()}r.parent&&(r.parent.container.forgetChild(n),r.parent.children.delete(n)),this.nodes.delete(n)}finally{e&&(this.insideRmComp=!1)}},t.prototype.errorHandler=function(t){if(!this.root.dash)throw new Error("Destroyed root component");this.root.dash.emit("log",{type:"error",messages:[t]},{sync:!0})},t.prototype.nextTick=function(t){var e=this;this.tickList?this.tickList.push(t):(this.tickList=[t],setTimeout(function(){if(e.tickList){for(var t=0,n=e.tickList;t<n.length;t++){var r=n[t];try{r()}catch(t){e.errorHandler(t)}}e.tickList=null}},0))},t.prototype.findNode=function(t){var e=this.nodes.get(t);if(!e)throw new Error("Missing node of component "+t);return e},t.prototype.newId=function(){return this.compCount++},t.prototype.createLog=function(t){for(var e=this,n={},r=function(t){n[t]=function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];if(!e.root.dash)throw new Error("Destroyed root component");e.root.dash.emit("log",{type:t,messages:n},{sync:!0})}},o=0,i=t;o<i.length;o++){var s=i[o];r(s)}return Object.freeze(n)},t.getComponentName=function(t){if("string"==typeof t.componentName)return t.componentName;if(t.constructor&&t.constructor.name)return t.constructor.name;var e=/function (.+)\(/.exec(t.toString());return e&&e.length>1?e[1]:"Function"},t}(),ChildEmitter=function(){function t(t){this.app=t,this.destroyed=!1}return t.prototype.emit=function(e,n,r){if(this.callbacks){var o=this.callbacks.get(e.eventName);if(o){for(var i=[],s=0,a=o;s<a.length;s++){var c=a[s];c.filter.componentName&&c.filter.componentName===e.sourceName||!c.filter.deep&&n||c.filter.group&&!t.hasGroup(c.filter.group,r)||i.push(c)}this.callCbList(i,e)}}},t.prototype.listen=function(t,e){var n=this;if(void 0===e&&(e={}),this.destroyed)throw new Error("Cannot call listen in a destroyed child-emitter");this.callbacks||(this.callbacks=new Map);var r=[],o=function(){return n.destroyed||!r},i={call:function(o,s,a){if(n.destroyed||!r||!n.callbacks)return i;var c=n.callbacks.get(t);c||n.callbacks.set(t,c=[]);var h=c.length;return r.push(h),"string"==typeof o?c[h]={mode:o,callback:s,thisArg:a,filter:e}:c[h]={mode:"eventOnly",callback:o,thisArg:s,filter:e},i},disable:function(){if(!o()&&n.callbacks){var e=n.callbacks.get(t);if(e)for(var i=0,s=r;i<s.length;i++){var a=s[i];delete e[a]}r=null}},isDisabled:o};return i},t.prototype.destroy=function(){this.callbacks=null,this.destroyed=!0},t.hasGroup=function(t,e){for(var n="string"==typeof t?[t]:t,r=0,o=n;r<o.length;r++){var i=o[r];if(e.has(i))return!0}return!1},t.prototype.callCbList=function(t,e){for(var n=0,r=t;n<r.length;n++){var o=r[n];try{call(o,e)}catch(t){this.app.errorHandler(t)}}},t}(),Container=function(){function t(t,e,n,r){this.app=t,this.componentName=e,this.componentId=n,this.emitter=new Emitter(t,["destroy"]),this.childEmitter=new ChildEmitter(t),this.bkb=makeBkb(this,r),this.dash=makeDash(this,this.bkb)}return t.prototype.makeInstance=function(t,e){this.setInstance(new(t.bind.apply(t,[void 0,this.dash].concat(e))))},t.prototype.setInstance=function(t){var e=this;if(!this.inst){if(!this.bkb)throw new Error("Destroyed component");if(t.bkb)throw new Error('A component cannot have a member "bkb"');Object.defineProperty(t,"bkb",{get:function(){return e.bkb}}),this.inst=t}},t.prototype.getInstance=function(){if(!this.inst){if(this.bkb)throw new Error("The component instance is still not initialized");throw new Error("Destroyed component")}return this.inst},t.prototype.destroy=function(){this.emit("destroy",void 0,{sync:!0}),this.app.removeComponent(this),this.childGroups&&this.childGroups.clear(),this.emitter.destroy(),this.childEmitter.destroy(),this.bkb=null,this.dash=null,this.inst=null},t.prototype.forgetChild=function(t){if(this.childGroups)for(var e=0,n=Array.from(this.childGroups.values());e<n.length;e++){var r=n[e];r.delete(t)}},t.prototype.createComponent=function(t,e,n){var r=this.app.createComponent(t,this,n,e);if(e.group){this.childGroups||(this.childGroups=new Map);for(var o="string"==typeof e.group?[e.group]:e.group,i=0,s=o;i<s.length;i++){var a=s[i],c=this.childGroups.get(a);c||this.childGroups.set(a,c=new Set),c.add(r.componentId)}}return r},t.prototype.broadcast=function(t,e){var n=this;e&&e.sync?this.emitter.emit(t):this.app.nextTick(function(){return n.emitter.emit(t)})},t.prototype.emit=function(t,e,n){var r=this;n&&n.sync?this.emitSync(this.createEvent(t,e)):this.app.nextTick(function(){return r.emitSync(r.createEvent(t,e))})},t.prototype.createEvent=function(e,n){var r=!0;return Object.freeze((o={eventName:e,sourceName:this.componentName,sourceId:this.componentId,source:this.getInstance(),data:n,stopPropagation:function(){r=!1}},o[t.canPropagateSymb]=function(){return r},o));var o},t.prototype.emitSync=function(t){this.emitter.emit(t);var e=this.app.getParentOf(this.componentId);e&&e.bubbleUpEvent(t,!1,this.componentId)},t.prototype.bubbleUpEvent=function(e,n,r){if(!e[t.canPropagateSymb]||e[t.canPropagateSymb]()){this.childEmitter.emit(e,n,this.getGroupsOf(r));var o=this.app.getParentOf(this.componentId);o&&o.bubbleUpEvent(e,!0,this.componentId)}},t.prototype.listenToParent=function(t,e){var n=this.getParent(e);if(n)return n.emitter.listen(t,this);if(e.componentName)throw new Error("Unknown parent "+e.componentName);return Emitter.empty()},t.prototype.listenTo=function(t,e){return this.app.getContainer(t.bkb.componentId).emitter.listen(e,this)},t.prototype.getGroupsOf=function(t){var e=new Set;if(this.childGroups)for(var n=0,r=Array.from(this.childGroups.entries());n<r.length;n++){var o=r[n],i=o[0],s=o[1];s.has(t)&&e.add(i)}return e},t.prototype.getParent=function(t){for(var e=this;e=this.app.getParentOf(e.componentId);)if(!t||!t.componentName||t.componentName===e.componentName)return e},t.prototype.find=function(t){if(t.deep)throw new Error('Cannot call "find" with filter deep');for(var e=this.getChildContainers(t.group),n=[],r=0,o=e;r<o.length;r++){var i=o[r];t.componentName&&t.componentName!==i.componentName||n.push(i.getInstance())}return n},t.prototype.findSingle=function(t){var e=this.find(t);if(1!==e.length)throw new Error("Cannot find single "+JSON.stringify(t)+" in "+this.componentName+" "+this.componentId);return e[0]},t.prototype.count=function(t){return this.find(t).length},t.prototype.has=function(t){return this.count(t)>0},t.prototype.getChildContainers=function(t){if(!t)return this.app.getChildrenOf(this.componentId);if(!this.childGroups)return[];for(var e="string"==typeof t?[t]:t,n=new Set,r=0,o=e;r<o.length;r++){var i=o[r],s=this.childGroups.get(i);if(s)for(var a=0,c=Array.from(s.values());a<c.length;a++){var h=c[a];n.add(h)}}for(var l=[],p=0,u=Array.from(n.values());p<u.length;p++){var h=u[p];l.push(this.app.getContainer(h))}return l},t}();Container.canPropagateSymb=Symbol("canPropagate");var Emitter=function(){function t(t,e){this.app=t,this.strictEvents=!1,this.destroyed=!1,this.fromEolCancelers=[],e&&this.exposeEvents(e,!1)}return t.empty=function(){var t={call:function(){return t},disable:function(){},isDisabled:function(){return!1}};return t},t.prototype.exposeEvents=function(t,e){if(this.destroyed)throw new Error("Cannot call exposeEvents in a destroyed transmitter");this.eventNames||(this.eventNames=new Set);for(var n=0,r=t;n<r.length;n++){var o=r[n];this.eventNames.add(o)}e&&(this.strictEvents=!0)},t.prototype.emit=function(t){if(this.callbacks){if(this.strictEvents&&this.eventNames&&!this.eventNames.has(t.eventName))throw new Error("Unexposed event: "+t.eventName);var e=this.callbacks.get(t.eventName);e&&this.callCbList(e,t)}},t.prototype.listen=function(t,e){var n=this;if(this.destroyed||!this.fromEolCancelers)throw new Error("Cannot call listen in a destroyed emitter");if(e&&!e.bkb)throw new Error("Cannot call listen from a destroyed component");this.callbacks||(this.callbacks=new Map);var r,o=[],i=function(){return n.destroyed||!o},s={call:function(e,r,i){if(n.destroyed||!o||!n.callbacks)return s;var a=n.callbacks.get(t);a||n.callbacks.set(t,a=[]);var c=a.length;return o.push(c),"string"==typeof e?a[c]={mode:e,callback:r,thisArg:i}:a[c]={mode:"eventOnly",callback:e,thisArg:r},s},disable:function(){if(!i()&&n.callbacks){var e=n.callbacks.get(t);if(e)for(var s=0,a=o;s<a.length;s++){var c=a[s];delete e[c]}o=null,r&&(r(),r=null)}},isDisabled:i};if(e){var a=e.bkb.listen("destroy").call(function(){return s.disable()}),c=this.fromEolCancelers.length;this.fromEolCancelers[c]=a,r=function(){a.disable(),n.fromEolCancelers&&delete n.fromEolCancelers[c]}}else r=null;return s},t.prototype.destroy=function(){if(this.fromEolCancelers)for(var t in this.fromEolCancelers)this.fromEolCancelers.hasOwnProperty(t)&&this.fromEolCancelers[t].disable();this.fromEolCancelers=null,this.callbacks=null,this.eventNames=null,this.destroyed=!0},t.prototype.callCbList=function(t,e){for(var n in t)if(t.hasOwnProperty(n))try{call(t[n],e)}catch(t){this.app.errorHandler(t)}},t}();
"use strict";function createApplication(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=new ApplicationContainer(t,!1,e);return r.root.getInstance()}function toApplication(t){var e=new ApplicationContainer(t,!0);return e.root.dash}function makeBkb(t,e){var n={get instance(){return t.getInstance()},get parent(){return this.getParent()},getParent:function(e){var n=t.getParent(e);return n?n.getInstance():void 0},on:function(e,n,r,o){return t.emitter.listen(e).call(n,r,o),this},listen:function(e){return t.emitter.listen(e)},destroy:function(){return t.destroy()},componentName:t.componentName,componentId:t.componentId,find:function(e){return void 0===e&&(e={}),t.find(e)},findSingle:function(e){return void 0===e&&(e={}),t.findSingle(e)},count:function(e){return void 0===e&&(e={}),t.count(e)},has:function(e){return void 0===e&&(e={}),t.has(e)}};return e&&Object.assign(n,e),Object.freeze(n),n}function makeDash(t,e){var n=Object.assign(Object.create(e),{setInstance:function(e){return t.setInstance(e)},exposeEvents:function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=1===e.length&&Array.isArray(e[0])?e[0]:e;return t.emitter.exposeEvents(r,!0),this},create:function(e,n){return void 0===n&&(n={}),t.createComponent(e,n,!1).getInstance()},toComponent:function(e,n){return void 0===n&&(n={}),t.createComponent(e,n,!0).dash},emit:function(e,n,r){for(var o=Array.isArray(e)?e:[e],i=0,a=o;i<a.length;i++){var s=a[i];t.emit(s,n,r)}return this},broadcast:function(e,n){return t.broadcast(e,n),this},listenToParent:function(e,n){return void 0===n&&(n={}),t.listenToParent(e,n)},listenToChildren:function(e,n){return t.childEmitter.listen(e,n)},listenTo:function(e,n){return t.listenTo(e,n)},bkb:e});return t.app.root&&t.app.root!==t&&Object.defineProperty(n,"app",{get:function(){return t.app.root.getInstance()}}),Object.freeze(n),n}function call(t,e){switch(t.mode){case"dataFirst":t.thisArg?t.callback.call(t.thisArg,e.data,e):t.callback(e.data,e);break;case"arguments":t.thisArg?t.callback.apply(t.thisArg,e.data):t.callback.apply(t,e.data);break;case"eventOnly":default:t.thisArg?t.callback.call(t.thisArg,e):t.callback(e)}}exports.createApplication=createApplication,exports.toApplication=toApplication;var ApplicationContainer=function(){function t(t,e,n){var r=this;this.compCount=0,this.nodes=new Map,this.tickList=null,this.insideRmComp=!1;var o=["error","warn","info","debug","trace"],i=this.newId();this.root=new Container(this,"root",i,{nextTick:function(t){return r.nextTick(t)},log:this.createLog(o)}),this.nodes.set(i,{container:this.root}),this.root.emitter.exposeEvents(["log"].concat(o,["addComponent","removeComponent","changeComponent"]),!1),e?this.root.setInstance(t):this.root.makeInstance(t,n||[])}return t.prototype.getParentOf=function(t){var e=this.findNode(t);return e.parent?e.parent.container:void 0},t.prototype.getChildrenOf=function(t){var e=[],n=this.findNode(t).children;if(n)for(var r=0,o=Array.from(n.values());r<o.length;r++){var i=o[r];e.push(i.container)}return e},t.prototype.getContainer=function(t){return this.findNode(t).container},t.prototype.createComponent=function(e,n,r,o){if(!this.root.dash)throw new Error("Destroyed root component");var i=o.componentName||t.getComponentName(e),a=this.newId(),s=new Container(this,i,a),c=this.findNode(n.componentId),h={container:s,parent:c};return this.nodes.set(a,h),c.children||(c.children=new Map),c.children.set(a,h),r?s.setInstance(e):s.makeInstance(e,o.args||[]),this.root.dash.emit("addComponent",{component:s.getInstance()}),this.root.dash.emit("changeComponent",{component:s.getInstance(),type:"add"}),s},t.prototype.removeComponent=function(t){if(!this.root.dash)throw new Error("Destroyed root component");var e=!this.insideRmComp;try{e&&(this.insideRmComp=!0,this.root.dash.emit("removeComponent",{component:t.getInstance()},{sync:!0}),this.root.dash.emit("changeComponent",{component:t.getInstance(),type:"remove"},{sync:!0}));var n=t.componentId,r=this.findNode(n);if(r.children){for(var o=0,i=Array.from(r.children.values());o<i.length;o++){var a=i[o];a.parent=null,a.container.destroy()}r.children.clear()}r.parent&&(r.parent.container.forgetChild(n),r.parent.children.delete(n)),this.nodes.delete(n)}finally{e&&(this.insideRmComp=!1)}},t.prototype.errorHandler=function(t){if(!this.root.dash)throw new Error("Destroyed root component");this.root.dash.emit("log",{type:"error",messages:[t]},{sync:!0})},t.prototype.nextTick=function(t){var e=this;this.tickList?this.tickList.push(t):(this.tickList=[t],setTimeout(function(){if(e.tickList){for(var t=0,n=e.tickList;t<n.length;t++){var r=n[t];try{r()}catch(t){e.errorHandler(t)}}e.tickList=null}},0))},t.prototype.findNode=function(t){var e=this.nodes.get(t);if(!e)throw new Error("Missing node of component "+t);return e},t.prototype.newId=function(){return this.compCount++},t.prototype.createLog=function(t){for(var e=this,n={},r=function(t){n[t]=function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];if(!e.root.dash)throw new Error("Destroyed root component");e.root.dash.emit("log",{type:t,messages:n},{sync:!0})}},o=0,i=t;o<i.length;o++){var a=i[o];r(a)}return Object.freeze(n)},t.getComponentName=function(t){if("string"==typeof t.componentName)return t.componentName;if(t.constructor&&t.constructor.name)return t.constructor.name;var e=/function (.+)\(/.exec(t.toString());return e&&e.length>1?e[1]:"Function"},t}(),ChildEmitter=function(){function t(t){this.app=t,this.destroyed=!1}return t.prototype.emit=function(e,n,r){if(this.callbacks){var o=this.callbacks.get(e.eventName);if(o){for(var i=[],a=0,s=o;a<s.length;a++){var c=s[a];c.filter.componentName&&c.filter.componentName===e.sourceName||!c.filter.deep&&n||c.filter.group&&!t.hasGroup(c.filter.group,r)||i.push(c)}this.callCbList(i,e)}}},t.prototype.listen=function(t,e){var n=this;if(void 0===e&&(e={}),this.destroyed)throw new Error("Cannot call listen in a destroyed child-emitter");this.callbacks||(this.callbacks=new Map);var r=[],o=function(){return n.destroyed||!r},i={call:function(o,a,s){if(n.destroyed||!r||!n.callbacks)return i;var c=n.callbacks.get(t);c||n.callbacks.set(t,c=[]);var h=c.length;return r.push(h),"string"==typeof o?c[h]={mode:o,callback:a,thisArg:s,filter:e}:c[h]={mode:"eventOnly",callback:o,thisArg:a,filter:e},i},disable:function(){if(!o()&&n.callbacks){var e=n.callbacks.get(t);if(e)for(var i=0,a=r;i<a.length;i++){var s=a[i];delete e[s]}r=null}},isDisabled:o};return i},t.prototype.destroy=function(){this.callbacks=null,this.destroyed=!0},t.hasGroup=function(t,e){for(var n="string"==typeof t?[t]:t,r=0,o=n;r<o.length;r++){var i=o[r];if(e.has(i))return!0}return!1},t.prototype.callCbList=function(t,e){for(var n=0,r=t;n<r.length;n++){var o=r[n];try{call(o,e)}catch(t){this.app.errorHandler(t)}}},t}(),Container=function(){function t(t,e,n,r){this.app=t,this.componentName=e,this.componentId=n,this.emitter=new Emitter(t,["destroy"]),this.childEmitter=new ChildEmitter(t),this.bkb=makeBkb(this,r),this.dash=makeDash(this,this.bkb)}return t.prototype.makeInstance=function(t,e){this.setInstance(new(t.bind.apply(t,[void 0,this.dash].concat(e))))},t.prototype.setInstance=function(t){var e=this;if(!this.inst){if(!this.bkb)throw new Error("Destroyed component");if(t.bkb)throw new Error('A component cannot have a member "bkb"');Object.defineProperty(t,"bkb",{get:function(){return e.bkb}}),this.inst=t}},t.prototype.getInstance=function(){if(!this.inst){if(this.bkb)throw new Error("The component instance is still not initialized");throw new Error("Destroyed component")}return this.inst},t.prototype.destroy=function(){this.emit("destroy",void 0,{sync:!0}),this.app.removeComponent(this),this.childGroups&&this.childGroups.clear(),this.emitter.destroy(),this.childEmitter.destroy(),this.bkb=null,this.dash=null,this.inst=null},t.prototype.forgetChild=function(t){if(this.childGroups)for(var e=0,n=Array.from(this.childGroups.values());e<n.length;e++){var r=n[e];r.delete(t)}},t.prototype.createComponent=function(t,e,n){var r=this.app.createComponent(t,this,n,e);if(e.group){this.childGroups||(this.childGroups=new Map);for(var o="string"==typeof e.group?[e.group]:e.group,i=0,a=o;i<a.length;i++){var s=a[i],c=this.childGroups.get(s);c||this.childGroups.set(s,c=new Set),c.add(r.componentId)}}return r},t.prototype.broadcast=function(t,e){var n=this;e&&e.sync?this.emitter.emit(t):this.app.nextTick(function(){return n.emitter.emit(t)})},t.prototype.emit=function(t,e,n){var r=this;n&&n.sync?this.emitSync(this.createEvent(t,e)):this.app.nextTick(function(){return r.emitSync(r.createEvent(t,e))})},t.prototype.createEvent=function(e,n){var r=!0;return Object.freeze((o={eventName:e,sourceName:this.componentName,sourceId:this.componentId,source:this.getInstance(),data:n,stopPropagation:function(){r=!1}},o[t.canPropagateSymb]=function(){return r},o));var o},t.prototype.emitSync=function(t){this.emitter.emit(t);var e=this.app.getParentOf(this.componentId);e&&e.bubbleUpEvent(t,!1,this.componentId)},t.prototype.bubbleUpEvent=function(e,n,r){if(!e[t.canPropagateSymb]||e[t.canPropagateSymb]()){this.childEmitter.emit(e,n,this.getGroupsOf(r));var o=this.app.getParentOf(this.componentId);o&&o.bubbleUpEvent(e,!0,this.componentId)}},t.prototype.listenToParent=function(t,e){var n=this.getParent(e);if(n)return n.emitter.listen(t,this);if(e.componentName)throw new Error("Unknown parent "+e.componentName);return Emitter.empty()},t.prototype.listenTo=function(t,e){return this.app.getContainer(t.bkb.componentId).emitter.listen(e,this)},t.prototype.getGroupsOf=function(t){var e=new Set;if(this.childGroups)for(var n=0,r=Array.from(this.childGroups.entries());n<r.length;n++){var o=r[n],i=o[0],a=o[1];a.has(t)&&e.add(i)}return e},t.prototype.getParent=function(t){for(var e=this;e=this.app.getParentOf(e.componentId);)if(!t||!t.componentName||t.componentName===e.componentName)return e},t.prototype.find=function(t){if(t.deep)throw new Error('Cannot call "find" with filter deep');for(var e=this.getChildContainers(t.group),n=[],r=0,o=e;r<o.length;r++){var i=o[r];t.componentName&&t.componentName!==i.componentName||n.push(i.getInstance())}return n},t.prototype.findSingle=function(t){var e=this.find(t);if(1!==e.length)throw new Error("Cannot find single "+JSON.stringify(t)+" in "+this.componentName+" "+this.componentId);return e[0]},t.prototype.count=function(t){return this.find(t).length},t.prototype.has=function(t){return this.count(t)>0},t.prototype.getChildContainers=function(t){if(!t)return this.app.getChildrenOf(this.componentId);if(!this.childGroups)return[];for(var e="string"==typeof t?[t]:t,n=new Set,r=0,o=e;r<o.length;r++){var i=o[r],a=this.childGroups.get(i);if(a)for(var s=0,c=Array.from(a.values());s<c.length;s++){var h=c[s];n.add(h)}}for(var l=[],p=0,u=Array.from(n.values());p<u.length;p++){var h=u[p];l.push(this.app.getContainer(h))}return l},t}();Container.canPropagateSymb=Symbol("canPropagate");var Emitter=function(){function t(t,e){this.app=t,this.strictEvents=!1,this.destroyed=!1,this.fromEolCancelers=[],e&&this.exposeEvents(e,!1)}return t.empty=function(){var t={call:function(){return t},disable:function(){},isDisabled:function(){return!1}};return t},t.prototype.exposeEvents=function(t,e){if(this.destroyed)throw new Error("Cannot call exposeEvents in a destroyed transmitter");this.eventNames||(this.eventNames=new Set);for(var n=0,r=t;n<r.length;n++){var o=r[n];this.eventNames.add(o)}e&&(this.strictEvents=!0)},t.prototype.emit=function(t){if(this.callbacks){if(this.strictEvents&&this.eventNames&&!this.eventNames.has(t.eventName))throw new Error("Unexposed event: "+t.eventName);var e=this.callbacks.get(t.eventName);e&&this.callCbList(e,t)}},t.prototype.listen=function(t,e){var n=this;if(this.destroyed||!this.fromEolCancelers)throw new Error("Cannot call listen in a destroyed emitter");if(e&&!e.bkb)throw new Error("Cannot call listen from a destroyed component");this.callbacks||(this.callbacks=new Map);var r,o=[],i=function(){return n.destroyed||!o},a={call:function(e,r,i){if(n.destroyed||!o||!n.callbacks)return a;var s=n.callbacks.get(t);s||n.callbacks.set(t,s=[]);var c=s.length;return o.push(c),"string"==typeof e?s[c]={mode:e,callback:r,thisArg:i}:s[c]={mode:"eventOnly",callback:e,thisArg:r},a},disable:function(){if(!i()&&n.callbacks){var e=n.callbacks.get(t);if(e)for(var a=0,s=o;a<s.length;a++){var c=s[a];delete e[c]}o=null,r&&(r(),r=null)}},isDisabled:i};if(e){var s=e.bkb.listen("destroy").call(function(){return a.disable()}),c=this.fromEolCancelers.length;this.fromEolCancelers[c]=s,r=function(){s.disable(),n.fromEolCancelers&&delete n.fromEolCancelers[c]}}else r=null;return a},t.prototype.destroy=function(){if(this.fromEolCancelers)for(var t in this.fromEolCancelers)this.fromEolCancelers.hasOwnProperty(t)&&this.fromEolCancelers[t].disable();this.fromEolCancelers=null,this.callbacks=null,this.eventNames=null,this.destroyed=!0},t.prototype.callCbList=function(t,e){for(var n in t)if(t.hasOwnProperty(n))try{call(t[n],e)}catch(t){this.app.errorHandler(t)}},t}();
{
"name": "bkb",
"version": "0.17.3",
"version": "0.17.4",
"description": "A JavaScript Framework for Front-end Applications.",

@@ -5,0 +5,0 @@ "main": "bkb.min.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc