Comparing version 0.28.1 to 0.28.2
@@ -1,1 +0,1 @@ | ||
function arr(t){return"string"==typeof t?[t]:t}function flatten(t){return 1===t.length&&Array.isArray(t[0])?t[0]:t}class DescendingOrderManager{constructor(t,e){this.app=t,this.componentId=e,this.map=new Map}invokeOrder(t,e){for(let s of arr(t))this.exec(s,e);let s=this.app.getChildrenOf(this.componentId);for(let r of s)r.getDOrders().invokeOrder(t,e)}listenToDescendingOrder(t,e,s=null){for(let r of arr(t)){let t=this.map.get(r);t||this.map.set(r,t=[]),t.push({cb:e,thisArg:s})}}stopListeningDescendingOrder(t,e,s=null){for(let r of arr(t)){let t=this.map.get(r);t&&this.map.set(r,t.filter(t=>t.cb!==e||t.thisArg!==s))}}exec(t,e){let s=this.map.get(t);s&&s.forEach(t=>call(t,e))}}function call(t,e){t.thisArg?t.cb.call(t.thisArg,e):t.cb(e)}function call$1(t,e){t.thisArg?t.cb.call(t.thisArg,e.data,e):t.cb(e.data,e)}class Emitter{constructor(t,e){this.log=t,this.eventNames=new Set,this.strictEvents=!1,this.destroyed=!1,e&&this.exposeEvent(e,!1)}exposeEvent(t,e){if(this.destroyed)throw new Error("Cannot call exposeEvent in a destroyed transmitter");for(let e of t)this.eventNames.add(e);e&&(this.strictEvents=!0)}emit(t){if(this.destroyed||!this.listeners)return;if(this.strictEvents&&!this.eventNames.has(t.eventName))throw new Error(`Unexposed event: ${t.eventName}`);let e=this.listeners.get(t.eventName);if(e)for(let s of e)try{call$1(s,t)}catch(t){this.log.error(t)}}on(t,e,s){if(!this.destroyed){this.listeners||(this.listeners=new Map);for(let r of t){let t=this.listeners.get(r);t||this.listeners.set(r,t=[]),t.push({cb:e,thisArg:s})}}}off(t,e,s){if(!this.destroyed&&this.listeners)for(let[r,i]of this.listeners)if(!t||t.has(r))for(let t=0;t<i.length;++t){let r=i[t];r.cb===e&&r.thisArg===s&&(i.splice(t,1),--t)}}destroy(){this.listeners=void 0,this.destroyed=!0}}class Subscriber{listenTo(t,e,s,r=null){t.on(e,s,r),this.map||(this.map=new Map);let i=this.map.get(s);i||this.map.set(s,i=new Map);let n=i.get(r);n||i.set(r,n=new Map);let o=n.get(t);o||n.set(t,o=new Set);for(let t of e)o.add(t)}stopListeningEverywhere(t,e=null){if(!this.map)return;let s=this.map.get(t);if(!s)return;let r=s.get(e);if(r){for(let[s,i]of r)s.off(i,t,e);s.delete(e),0===s.size&&this.map.delete(t)}}stopListening(t,e,s,r=null){if(!this.map)return;let i=this.map.get(s);if(!i)return;let n=i.get(r);if(!n)return;let o=n.get(t);if(!o)return;let h=new Set;for(let t of e)o.delete(t)&&h.add(t);t.off(h,s,r),0===o.size&&(n.delete(t),0===n.size&&(i.delete(r),0===i.size&&this.map.delete(s)))}destroy(){if(this.map){for(let[t,e]of this.map)for(let[s,r]of e)for(let[e,i]of r)e.off(i,t,s);this.map=void 0}}}const CAN_PROPAGATE_SYMB=Symbol("canPropagate");class Bkb{constructor(t,e){this.app=t,this.componentId=e,this.subscriber=new Subscriber,this.emitter=new Emitter(t.log,["destroy"]),this.pub=makePublicDash(this),this.dash=makeDash(this,this.pub)}makeInstance(t,e){if(this.inst)return;let s;try{s=new t(this.dash,e)}catch(t){throw this.destroy(),t}this.setInstance(s)}setInstance(t){if(!this.pub)throw new Error("Destroyed component");if(this.inst){if(t!==this.inst)throw new Error("Conflict between component instances")}else this.inst=t,this.app.setInstanceOf(this.componentId,this.inst)}getInstance(){if(!this.inst){if(this.pub)throw new Error("The component instance is still not initialized");throw new Error("Destroyed component")}return this.inst}destroy(){this.emit("destroy",void 0,{sync:!0,cancelPropagation:!0}),this.app.removeComponent(this,this.inst),this.childGroups&&this.childGroups.clear(),this.emitter.destroy(),this.subscriber.destroy(),this.pub=void 0,this.dash=void 0,this.inst=void 0}forgetChild(t){if(this.childGroups)for(let e of this.childGroups.values())e.delete(t)}createChild(t){return this.app.createComponent(t,this)}addToGroup(t,e){let s=this.app.getBkbByInst(t).componentId;if(this!==this.app.getParentOf(s))throw new Error(`The component ${s} is not a child of ${this.componentId}`);this.childGroups||(this.childGroups=new Map);for(let t of e){let e=this.childGroups.get(t);e||this.childGroups.set(t,e=new Set),e.add(s)}}inGroup(t,e){if(!this.childGroups)return!1;let s=this.app.getBkbByInst(t).componentId;for(let t of e){let e=this.childGroups.get(t);if(e&&e.has(s))return!0}return!1}broadcast(t,e={}){e.sync?this.emitter.emit(t):this.app.asyncCall(()=>this.emitter.emit(t))}emit(t,e,s={}){s.sync?this.emitSync(this.createEvent(t,e,s.cancelPropagation)):this.app.asyncCall(()=>this.emitSync(this.createEvent(t,e,s.cancelPropagation)))}getParent(){return this.app.getParentOf(this.componentId)}getParents(){let t=this,e=[];for(;t=this.app.getParentOf(t.componentId);)e.push(t);return e}getChildren(t){let e=this.getChildBkbs(t.group),s=[];for(let r of e)!r.inst||t.filter&&!t.filter(r)||s.push(r.inst);return s}hasChildren(t){return this.getChildren(t).length>0}isChild(t){let e=this.app.getBkbByInst(t).componentId;return this===this.app.getParentOf(e)}destroyChildren(t){let e=this.getChildBkbs(t.group);for(let s of e)t.filter&&!t.filter(s)||s.destroy()}getDOrders(){return this.dOrders||(this.dOrders=new DescendingOrderManager(this.app,this.componentId)),this.dOrders}createEvent(t,e,s){let r=this,i=!s;return Object.freeze({eventName:t,get source(){return r.getInstance()},data:e,stopPropagation:()=>{i=!1},[CAN_PROPAGATE_SYMB]:()=>i})}emitSync(t){if(this.emitter.emit(t),t[CAN_PROPAGATE_SYMB]&&t[CAN_PROPAGATE_SYMB]()){let e=this.app.getParentOf(this.componentId);e&&e.emitSync(t)}}getChildBkbs(t){if(!t)return this.app.getChildrenOf(this.componentId);if(!this.childGroups)return[];let e="string"==typeof t?[t]:t,s=new Set;for(let t of e){let e=this.childGroups.get(t);if(e)for(let t of e.values())s.add(t)}let r=[];for(let t of s.values())r.push(this.app.getBkb(t));return r}}function makePublicDash(t){return Object.freeze({unmanagedListeners:Object.freeze({on:(e,s,r)=>{t.emitter.on(arr(e),s,r)},off:(e,s,r)=>{t.emitter.off(new Set(arr(e)),s,r)}}),getComponent:()=>t.getInstance(),children:(e={})=>t.getChildren(e),hasChildren:(e={})=>t.hasChildren(e),isChild:e=>t.isChild(e),destroy:()=>t.destroy(),invokeDescendingOrder(e,s){return t.getDOrders().invokeOrder(e,s),this},isComponent:e=>t.app.isComponent(e),getPublicDashOf:e=>t.app.getBkbByInst(e).pub,getParentOf(e){let s=t.app.getBkbByInst(e).getParent();return s?s.getInstance():void 0},log:t.app.log,get app(){return t.app.root.getInstance()}})}function makeDash(t,e){let s={setInstance:e=>(t.setInstance(e),r),exposeEvent:(...e)=>(t.emitter.exposeEvent(flatten(e),!0),r),create:(e,s)=>t.createChild({asObj:!1,Class:e,opt:s}).getInstance(),registerComponent:e=>t.createChild({asObj:!0,obj:e}).dash,addToGroup:(e,...s)=>(t.addToGroup(e,flatten(s)),r),inGroup:(e,...s)=>t.inGroup(e,flatten(s)),emit(e,s,i){let n=Array.isArray(e)?e:[e];for(let e of n)t.emit(e,s,i);return r},broadcast:(e,s)=>(t.broadcast(e,s),r),listenTo:(...e)=>{let s,i,n,o;if(2===e.length||"string"==typeof e[0]||Array.isArray(e[0]))[i,n,o]=e,s=t;else{let r;[r,i,n,o]=e,s=t.app.getBkbByInst(r)}return t.subscriber.listenTo(s.emitter,arr(i),n,o),r},stopListening:(...e)=>{let s,i,n,o,h=e.length;if("string"==typeof e[0]||Array.isArray(e[0]))[i,n,o]=e,s=t;else{if(1===h||2===h)return[n,o]=e,void t.subscriber.stopListeningEverywhere(n,o);{let r;[r,i,n,o]=e,s=t.app.getBkbByInst(r)}}return t.subscriber.stopListening(s.emitter,arr(i),n,o),r},listenToDescendingOrder:(e,s,i)=>(t.getDOrders().listenToDescendingOrder(e,s,i),r),stopListeningDescendingOrder:(e,s,i)=>(t.getDOrders().stopListeningDescendingOrder(e,s,i),r),destroyChildren:(e={})=>(t.destroyChildren(e),r),publicDash:e},r=Object.assign(Object.create(e),s);return Object.assign(r,...t.app.augmentList.map(t=>t(r))),t.app.root&&t.app.root!==t||(r.addDashAugmentation=(e=>{t.app.augmentList.push(e)})),Object.freeze(r),r}class AppBkb{constructor(t,e,s){this.augmentList=[],this.compCount=0,this.nodesByInst=new WeakMap,this.nodes=new Map,this.insideRmComp=!1;let r=this.newId();this.log=this.createLog(["error","warn","info","debug","trace"]),this.root=new Bkb(this,r);let i={bkb:this.root};this.nodes.set(r,i),this.root.emitter.exposeEvent(["log","addComponent","removeComponent","changeComponent"],!1),e?this.root.setInstance(t):this.root.makeInstance(t,s),i.created=!0}setInstanceOf(t,e){let s=this.nodes.get(t);if(!s)throw new Error("Destroyed component");this.nodesByInst.set(e,s)}getParentOf(t){let e=this.findNode(t);return e.parent?e.parent.bkb:void 0}getChildrenOf(t){let e=[],s=this.findNode(t).children;if(s)for(let t of s.values())e.push(t.bkb);return e}getBkb(t){return this.findNode(t).bkb}getBkbByInst(t){return this.findNodeByInst(t).bkb}isComponent(t){return!!this.nodesByInst.get(t)}createComponent(t,e){if(!this.root.dash)throw new Error("Destroyed root component");let s=this.newId(),r=new Bkb(this,s),i=this.findNode(e.componentId),n={bkb:r,parent:i};return this.nodes.set(s,n),i.children||(i.children=new Map),i.children.set(s,n),t.asObj?r.setInstance(t.obj):r.makeInstance(t.Class,t.opt),this.root.dash.emit(["addComponent","changeComponent"],{component:r.getInstance(),type:"add"}),n.created=!0,r}removeComponent(t,e){if(!this.root.dash)throw new Error("Destroyed root component");let s=!this.insideRmComp;try{let r=t.componentId,i=this.findNode(r);if(s&&(this.insideRmComp=!0,e&&i.created)){let t={component:e,type:"remove"};this.root.dash.emit(["removeComponent","changeComponent"],t,{sync:!0})}if(i.children){for(let t of i.children.values())t.parent=void 0,t.bkb.destroy();i.children.clear()}i.parent&&(i.parent.bkb.forgetChild(r),i.parent.children.delete(r)),this.nodes.delete(r),e&&this.nodesByInst.delete(e)}finally{s&&(this.insideRmComp=!1)}}asyncCall(t){this.tickList?this.tickList.push(t):(this.tickList=[t],setTimeout(()=>{if(this.tickList){for(let t of this.tickList)try{t()}catch(t){this.log.error(t)}this.tickList=void 0}},0))}findNode(t){let e=this.nodes.get(t);if(!e)throw new Error(`Missing node of component "${t}"`);return e}findNodeByInst(t){let e=this.nodesByInst.get(t);if(!e)throw new Error(`Cannot find a component for the instance: ${t}`);return e}newId(){return this.compCount++}createLog(t){let e={},s=0;for(let r of t)e[r]=((...t)=>{if(!this.root.dash)throw new Error("Destroyed root component");this.root.dash.emit("log",{level:r,messages:t,levelNumber:++s},{sync:!0})});return Object.freeze(e)}}function createApplication(t,e){return new AppBkb(t,!1,e).root.getInstance()}function registerApplication(t){return new AppBkb(t,!0).root.dash}export{createApplication,registerApplication}; | ||
function t(t){return"string"==typeof t?[t]:t}function e(t){return 1===t.length&&Array.isArray(t[0])?t[0]:t}class s{constructor(t,e){this.app=t,this.componentId=e,this.map=new Map}invokeOrder(e,s){for(let i of t(e))this.exec(i,s);let i=this.app.getChildrenOf(this.componentId);for(let t of i)t.getDOrders().invokeOrder(e,s)}listenToDescendingOrder(e,s,i=null){for(let n of t(e)){let t=this.map.get(n);t||this.map.set(n,t=[]),t.push({cb:s,thisArg:i})}}stopListeningDescendingOrder(e,s,i=null){for(let n of t(e)){let t=this.map.get(n);t&&this.map.set(n,t.filter(t=>t.cb!==s||t.thisArg!==i))}}exec(t,e){let s=this.map.get(t);s&&s.forEach(t=>(function(t,e){t.thisArg?t.cb.call(t.thisArg,e):t.cb(e)})(t,e))}}function i(t,e){t.thisArg?t.cb.call(t.thisArg,e.data,e):t.cb(e.data,e)}class n{constructor(t,e){this.log=t,this.eventNames=new Set,this.strictEvents=!1,this.destroyed=!1,e&&this.exposeEvent(e,!1)}exposeEvent(t,e){if(this.destroyed)throw new Error("Cannot call exposeEvent in a destroyed transmitter");for(let e of t)this.eventNames.add(e);e&&(this.strictEvents=!0)}emit(t){if(this.destroyed||!this.listeners)return;if(this.strictEvents&&!this.eventNames.has(t.eventName))throw new Error(`Unexposed event: ${t.eventName}`);let e=this.listeners.get(t.eventName);if(e)for(let s of e)try{i(s,t)}catch(t){this.log.error(t)}}on(t,e,s){if(!this.destroyed){this.listeners||(this.listeners=new Map);for(let i of t){let t=this.listeners.get(i);t||this.listeners.set(i,t=[]),t.push({cb:e,thisArg:s})}}}off(t,e,s){if(!this.destroyed&&this.listeners)for(let[i,n]of this.listeners)if(!t||t.has(i))for(let t=0;t<n.length;++t){let i=n[t];i.cb===e&&i.thisArg===s&&(n.splice(t,1),--t)}}destroy(){this.listeners=void 0,this.destroyed=!0}}class r{listenTo(t,e,s,i=null){t.on(e,s,i),this.map||(this.map=new Map);let n=this.map.get(s);n||this.map.set(s,n=new Map);let r=n.get(i);r||n.set(i,r=new Map);let o=r.get(t);o||r.set(t,o=new Set);for(let t of e)o.add(t)}stopListeningEverywhere(t,e=null){if(!this.map)return;let s=this.map.get(t);if(!s)return;let i=s.get(e);if(i){for(let[s,n]of i)s.off(n,t,e);s.delete(e),0===s.size&&this.map.delete(t)}}stopListening(t,e,s,i=null){if(!this.map)return;let n=this.map.get(s);if(!n)return;let r=n.get(i);if(!r)return;let o=r.get(t);if(!o)return;let h=new Set;for(let t of e)o.delete(t)&&h.add(t);t.off(h,s,i),0===o.size&&(r.delete(t),0===r.size&&(n.delete(i),0===n.size&&this.map.delete(s)))}destroy(){if(this.map){for(let[t,e]of this.map)for(let[s,i]of e)for(let[e,n]of i)e.off(n,t,s);this.map=void 0}}}const o=Symbol("canPropagate");class h{constructor(s,i){var o;this.app=s,this.componentId=i,this.subscriber=new r,this.emitter=new n(s.log,["destroy"]),this.pub=(o=this,Object.freeze({unmanagedListeners:Object.freeze({on:(e,s,i)=>{o.emitter.on(t(e),s,i)},off:(e,s,i)=>{o.emitter.off(new Set(t(e)),s,i)}}),getComponent:()=>o.getInstance(),children:(t={})=>o.getChildren(t),hasChildren:(t={})=>o.hasChildren(t),isChild:t=>o.isChild(t),destroy:()=>o.destroy(),invokeDescendingOrder(t,e){return o.getDOrders().invokeOrder(t,e),this},isComponent:t=>o.app.isComponent(t),getPublicDashOf:t=>o.app.getBkbByInst(t).pub,getParentOf(t){let e=o.app.getBkbByInst(t).getParent();return e?e.getInstance():void 0},log:o.app.log,get app(){return o.app.root.getInstance()}})),this.dash=function(s,i){let n={setInstance:t=>(s.setInstance(t),r),exposeEvent:(...t)=>(s.emitter.exposeEvent(e(t),!0),r),create:(t,e)=>s.createChild({asObj:!1,Class:t,opt:e}).getInstance(),registerComponent:t=>s.createChild({asObj:!0,obj:t}).dash,addToGroup:(t,...i)=>(s.addToGroup(t,e(i)),r),inGroup:(t,...i)=>s.inGroup(t,e(i)),emit(t,e,i){let n=Array.isArray(t)?t:[t];for(let t of n)s.emit(t,e,i);return r},broadcast:(t,e)=>(s.broadcast(t,e),r),listenTo:(...e)=>{let i,n,o,h;if(2===e.length||"string"==typeof e[0]||Array.isArray(e[0]))[n,o,h]=e,i=s;else{let t;[t,n,o,h]=e,i=s.app.getBkbByInst(t)}return s.subscriber.listenTo(i.emitter,t(n),o,h),r},stopListening:(...e)=>{let i,n,o,h,a=e.length;if("string"==typeof e[0]||Array.isArray(e[0]))[n,o,h]=e,i=s;else{if(1===a||2===a)return[o,h]=e,void s.subscriber.stopListeningEverywhere(o,h);{let t;[t,n,o,h]=e,i=s.app.getBkbByInst(t)}}return s.subscriber.stopListening(i.emitter,t(n),o,h),r},listenToDescendingOrder:(t,e,i)=>(s.getDOrders().listenToDescendingOrder(t,e,i),r),stopListeningDescendingOrder:(t,e,i)=>(s.getDOrders().stopListeningDescendingOrder(t,e,i),r),destroyChildren:(t={})=>(s.destroyChildren(t),r),publicDash:i},r=Object.assign(Object.create(i),n);Object.assign(r,...s.app.augmentList.map(t=>t(r))),s.app.root&&s.app.root!==s||(r.addDashAugmentation=(t=>{s.app.augmentList.push(t)}));return Object.freeze(r),r}(this,this.pub)}makeInstance(t,e){if(this.inst)return;let s;try{s=new t(this.dash,e)}catch(t){throw this.destroy(),t}this.setInstance(s)}setInstance(t){if(!this.pub)throw new Error("Destroyed component");if(this.inst){if(t!==this.inst)throw new Error("Conflict between component instances")}else this.inst=t,this.app.setInstanceOf(this.componentId,this.inst)}getInstance(){if(!this.inst){if(this.pub)throw new Error("The component instance is still not initialized");throw new Error("Destroyed component")}return this.inst}destroy(){this.emit("destroy",void 0,{sync:!0,cancelPropagation:!0}),this.app.removeComponent(this,this.inst),this.childGroups&&this.childGroups.clear(),this.emitter.destroy(),this.subscriber.destroy(),this.pub=void 0,this.dash=void 0,this.inst=void 0}forgetChild(t){if(this.childGroups)for(let e of this.childGroups.values())e.delete(t)}createChild(t){return this.app.createComponent(t,this)}addToGroup(t,e){let s=this.app.getBkbByInst(t).componentId;if(this!==this.app.getParentOf(s))throw new Error(`The component ${s} is not a child of ${this.componentId}`);this.childGroups||(this.childGroups=new Map);for(let t of e){let e=this.childGroups.get(t);e||this.childGroups.set(t,e=new Set),e.add(s)}}inGroup(t,e){if(!this.childGroups)return!1;let s=this.app.getBkbByInst(t).componentId;for(let t of e){let e=this.childGroups.get(t);if(e&&e.has(s))return!0}return!1}broadcast(t,e={}){e.sync?this.emitter.emit(t):this.app.asyncCall(()=>this.emitter.emit(t))}emit(t,e,s={}){s.sync?this.emitSync(this.createEvent(t,e,s.cancelPropagation)):this.app.asyncCall(()=>this.emitSync(this.createEvent(t,e,s.cancelPropagation)))}getParent(){return this.app.getParentOf(this.componentId)}getParents(){let t=this,e=[];for(;t=this.app.getParentOf(t.componentId);)e.push(t);return e}getChildren(t){let e=this.getChildBkbs(t.group),s=[];for(let i of e)!i.inst||t.filter&&!t.filter(i)||s.push(i.inst);return s}hasChildren(t){return this.getChildren(t).length>0}isChild(t){let e=this.app.getBkbByInst(t).componentId;return this===this.app.getParentOf(e)}destroyChildren(t){let e=this.getChildBkbs(t.group);for(let s of e)t.filter&&!t.filter(s)||s.destroy()}getDOrders(){return this.dOrders||(this.dOrders=new s(this.app,this.componentId)),this.dOrders}createEvent(t,e,s){let i=this,n=!s;return Object.freeze({eventName:t,get source(){return i.getInstance()},data:e,stopPropagation:()=>{n=!1},[o]:()=>n})}emitSync(t){if(this.emitter.emit(t),t[o]&&t[o]()){let e=this.app.getParentOf(this.componentId);e&&e.emitSync(t)}}getChildBkbs(t){if(!t)return this.app.getChildrenOf(this.componentId);if(!this.childGroups)return[];let e="string"==typeof t?[t]:t,s=new Set;for(let t of e){let e=this.childGroups.get(t);if(e)for(let t of e.values())s.add(t)}let i=[];for(let t of s.values())i.push(this.app.getBkb(t));return i}}class a{constructor(t,e,s){this.augmentList=[],this.compCount=0,this.nodesByInst=new WeakMap,this.nodes=new Map,this.insideRmComp=!1;let i=this.newId();this.log=this.createLog(["error","warn","info","debug","trace"]),this.root=new h(this,i);let n={bkb:this.root};this.nodes.set(i,n),this.root.emitter.exposeEvent(["log","addComponent","removeComponent","changeComponent"],!1),e?this.root.setInstance(t):this.root.makeInstance(t,s),n.created=!0}setInstanceOf(t,e){let s=this.nodes.get(t);if(!s)throw new Error("Destroyed component");this.nodesByInst.set(e,s)}getParentOf(t){let e=this.findNode(t);return e.parent?e.parent.bkb:void 0}getChildrenOf(t){let e=[],s=this.findNode(t).children;if(s)for(let t of s.values())e.push(t.bkb);return e}getBkb(t){return this.findNode(t).bkb}getBkbByInst(t){return this.findNodeByInst(t).bkb}isComponent(t){return!!this.nodesByInst.get(t)}createComponent(t,e){if(!this.root.dash)throw new Error("Destroyed root component");let s=this.newId(),i=new h(this,s),n=this.findNode(e.componentId),r={bkb:i,parent:n};return this.nodes.set(s,r),n.children||(n.children=new Map),n.children.set(s,r),t.asObj?i.setInstance(t.obj):i.makeInstance(t.Class,t.opt),this.root.dash.emit(["addComponent","changeComponent"],{component:i.getInstance(),type:"add"}),r.created=!0,i}removeComponent(t,e){if(!this.root.dash)throw new Error("Destroyed root component");let s=!this.insideRmComp;try{let i=t.componentId,n=this.findNode(i);if(s&&(this.insideRmComp=!0,e&&n.created)){let t={component:e,type:"remove"};this.root.dash.emit(["removeComponent","changeComponent"],t,{sync:!0})}if(n.children){for(let t of n.children.values())t.parent=void 0,t.bkb.destroy();n.children.clear()}n.parent&&(n.parent.bkb.forgetChild(i),n.parent.children.delete(i)),this.nodes.delete(i),e&&this.nodesByInst.delete(e)}finally{s&&(this.insideRmComp=!1)}}asyncCall(t){this.tickList?this.tickList.push(t):(this.tickList=[t],setTimeout(()=>{if(this.tickList){for(let t of this.tickList)try{t()}catch(t){this.log.error(t)}this.tickList=void 0}},0))}findNode(t){let e=this.nodes.get(t);if(!e)throw new Error(`Missing node of component "${t}"`);return e}findNodeByInst(t){let e=this.nodesByInst.get(t);if(!e)throw new Error(`Cannot find a component for the instance: ${t}`);return e}newId(){return this.compCount++}createLog(t){let e={},s=0;for(let i of t)e[i]=((...t)=>{if(!this.root.dash)throw new Error("Destroyed root component");this.root.dash.emit("log",{level:i,messages:t,levelNumber:++s},{sync:!0})});return Object.freeze(e)}}function d(t,e){return new a(t,!1,e).root.getInstance()}function l(t){return new a(t,!0).root.dash}export{d as createApplication,l as registerApplication}; |
@@ -5,3 +5,3 @@ const { promisify } = require("util") | ||
const rollup = require("rollup") | ||
const uglifyEs = require("uglify-es") | ||
const uglify = require("uglify-es") | ||
@@ -20,3 +20,3 @@ const readFile = promisify(fs.readFile) | ||
}) | ||
let { code } = await bundle.generate({ | ||
let { output } = await bundle.generate({ | ||
format: "es", | ||
@@ -26,3 +26,6 @@ sourcemap: false | ||
let minified = uglifyEs.minify(code) | ||
let minified = uglify.minify( | ||
{ "bkb.js": output[0].code }, | ||
{ toplevel: true } | ||
) | ||
if (minified.error) | ||
@@ -29,0 +32,0 @@ throw minified.error |
{ | ||
"name": "bkb", | ||
"version": "0.28.1", | ||
"description": "An Unopinionated JavaScript Framework for Front-end Applications", | ||
"version": "0.28.2", | ||
"description": "An Unopinionated JavaScript Framework for Front-end Applications.", | ||
"main": "bkb.min.js", | ||
"types": "bkb.d.ts", | ||
"devDependencies": { | ||
"npm-run-all": "4.1.2", | ||
"rimraf": "2.6.2", | ||
"rollup": "0.57.1", | ||
"tslint": "^5.11.0", | ||
"typescript": "2.8.1", | ||
"uglify-es": "3.3.9" | ||
"npm-run-all": "^4.1.5", | ||
"rimraf": "^2.6.3", | ||
"rollup": "^1.16.7", | ||
"tslint": "^5.18.0", | ||
"typescript": "^3.5.3", | ||
"uglify-es": "^3.3.9" | ||
}, | ||
@@ -37,3 +37,4 @@ "scripts": { | ||
"unopinionated" | ||
] | ||
], | ||
"dependencies": {} | ||
} |
{ | ||
"compilerOptions": { | ||
"target": "es2017", | ||
"target": "es2018", | ||
"lib": [ | ||
"dom", | ||
"es2016", | ||
"es2017.object" | ||
"es2018" | ||
], | ||
@@ -9,0 +8,0 @@ "strict": true, |
88817
18
2069