UNPKG

@thednp/event-listener

Version:

🚅 Modern event listener for efficient web applications based on subscribe-publish pattern.

3 lines (2 loc) • 767 B
var Listener=function(s){"use strict";const v="2.0.10",e={},f=o=>{const{type:i,currentTarget:c}=o;e[i].forEach((r,t)=>{c===t&&r.forEach((n,a)=>{a.apply(t,[o]),typeof n=="object"&&n.once&&d(t,i,a,n)})})},g=(o,i,c,r)=>{e[i]||(e[i]=new Map);const t=e[i];t.has(o)||t.set(o,new Map);const n=t.get(o),{size:a}=n;n.set(c,r),a||o.addEventListener(i,f,r)},d=(o,i,c,r)=>{const t=e[i],n=t&&t.get(o),a=n&&n.get(c),M=a!==void 0?a:r;n&&n.has(c)&&n.delete(c),t&&(!n||!n.size)&&t.delete(o),(!t||!t.size)&&delete e[i],(!n||!n.size)&&o.removeEventListener(i,f,M)},L=g,E=d;return s.addListener=g,s.globalListener=f,s.off=E,s.on=L,s.registry=e,s.removeListener=d,s.version=v,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"}),s}({}); //# sourceMappingURL=event-listener.js.map