lwc
Version:
Lightning Web Components (LWC)
2 lines (1 loc) • 2.5 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).WireService={})}(this,(function(e){"use strict";function t(e){return void 0===e}class n{constructor(e){this.type="ValueChangedEvent",this.value=e}}const{freeze:i,defineProperty:r,isExtensible:s}=Object,c="$$DeprecatedWiredElementHostKey$$",a="$$DeprecatedWiredParamsMetaKey$$";const{forEach:o,splice:d,indexOf:l}=Array.prototype,h="connect",u="disconnect",f="config";function p(e,t){const n=l.call(e,t);n>-1&&d.call(e,n,1)}e.ValueChangedEvent=n,e.register=function(e,d){if(null==e||!s(e))throw new TypeError("adapter id must be extensible");if("function"!=typeof d)throw new TypeError("adapter factory must be a callable");if("adapter"in e)throw new TypeError("adapter id is already associated to an adapter factory");const l=class extends class{constructor(e){this.connecting=[],this.disconnecting=[],this.configuring=[],this.isFirstUpdate=!0,this.callback=e,this.wiredElementHost=e[c],this.dynamicParamsNames=e[a],this.eventTarget={addEventListener:(e,t)=>{switch(e){case h:this.connecting.push(t);break;case u:this.disconnecting.push(t);break;case f:this.configuring.push(t),void 0!==this.currentConfig&&t.call(void 0,this.currentConfig);break;default:throw new Error(`Invalid event type ${e}.`)}},removeEventListener:(e,t)=>{switch(e){case h:p(this.connecting,t);break;case u:p(this.disconnecting,t);break;case f:p(this.configuring,t);break;default:throw new Error(`Invalid event type ${e}.`)}},dispatchEvent:e=>{if(!(e instanceof n)){if("wirecontextevent"===e.type)return this.wiredElementHost.dispatchEvent(e);throw new Error(`Invalid event type ${e.type}.`)}{const t=e.value;this.callback(t)}return!1}}}update(e){var n,i;(!this.isFirstUpdate||(this.isFirstUpdate=!1,function(e){return 0===Object.keys(e).length}(e)||function(e,n){return 0===n.length||n.some((n=>!t(e[n])))}(e,this.dynamicParamsNames)))&&((t(this.currentConfig)||(n=e,i=this.currentConfig,this.dynamicParamsNames.some((e=>n[e]!==i[e]))))&&(this.currentConfig=e,o.call(this.configuring,(t=>{t.call(void 0,e)}))))}connect(){o.call(this.connecting,(e=>e.call(void 0)))}disconnect(){o.call(this.disconnecting,(e=>e.call(void 0)))}}{constructor(e){super(e),d(this.eventTarget)}};i(l),i(l.prototype),r(e,"adapter",{writable:!1,configurable:!1,value:l})},e.registerWireService=function(){},Object.defineProperty(e,"__esModule",{value:!0})}));