Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/okikio/native. An initiative which aims to make it easy to create complex, light-weight, and perfor okikio.github.io/native
Something went wrong. Try again.
123var EventEmitter=function(i){"use strict";class l{constructor(a){this.map=new Map(a)}getMap(){return this.map}get(a){return this.map.get(a)}keys(){return Array.from(this.map.keys())}values(){return Array.from(this.map.values())}set(a,b){return this.map.set(a,b),this}add(a){let b=this.size,d=b;return this.set(d,a),this}get size(){return this.map.size}last(a=1){let b=this.keys()[this.size-a];return this.get(b)}prev(){return this.last(2)}delete(a){return this.map.delete(a),this}clear(){return this.map.clear(),this}has(a){return this.map.has(a)}entries(){return this.map.entries()}forEach(a=(...d)=>{},b){return this.map.forEach(a,b),this}[Symbol.iterator](){return this.entries()}methodCall(a,...b){return this.forEach(d=>{d[a](...b)}),this}async asyncMethodCall(a,...b){for(let[,d]of this.map)await d[a](...b);return this}}class k{constructor({callback:a=()=>{},scope:b=null,name:d="event"}){this.listener={callback:a,scope:b,name:d}}getCallback(){return this.listener.callback}getScope(){return this.listener.scope}getEventName(){return this.listener.name}toJSON(){return this.listener}}class j extends l{constructor(a="event"){super();this.name=a}}class m extends l{constructor(){super()}getEvent(a){let b=this.get(a);return b instanceof j?b:(this.set(a,new j(a)),this.get(a))}newListener(a,b,d){let c=this.getEvent(a);return c.add(new k({name:a,callback:b,scope:d})),c}on(a,b,d){if(typeof a=="undefined")return this;typeof a=="string"&&(a=a.trim().split(/\s/g));let c,e,f=typeof a=="object"&&!Array.isArray(a),h=f?b:d;return f||(e=b),Object.keys(a).forEach(g=>{f?(c=g,e=a[g]):c=a[g],this.newListener(c,e,h)},this),this}removeListener(a,b,d){let c=this.get(a);if(c instanceof j&&b){let e=new k({name:a,callback:b,scope:d});c.forEach((f,h)=>{if(f.getCallback()===e.getCallback()&&f.getScope()===e.getScope())return c.delete(h)})}return c}off(a,b,d){if(typeof a=="undefined")return this;typeof a=="string"&&(a=a.trim().split(/\s/g));let c,e,f=typeof a=="object"&&!Array.isArray(a),h=f?b:d;return f||(e=b),Object.keys(a).forEach(g=>{f?(c=g,e=a[g]):c=a[g],typeof e==="function"?this.removeListener(c,e,h):this.delete(c)},this),this}once(a,b,d){if(typeof a=="undefined")return this;typeof a=="string"&&(a=a.trim().split(/\s/g));let c,e,f=typeof a==="object"&&!Array.isArray(a),h=f?b:d;return f||(e=b),Object.keys(a).forEach(g=>{f?(c=g,e=a[g]):c=a[g];let n=(...o)=>{f?(c=g,e=a[g]):c=a[g],this.off(c,n,h),e.apply(h,o)};this.on(c,n,h)},this),this}emit(a,...b){return typeof a=="undefined"?this:(typeof a=="string"&&(a=a.trim().split(/\s/g)),a.forEach(d=>{let c=this.get(d);c instanceof j&&c.forEach(e=>{let{callback:f,scope:h}=e.toJSON();f.apply(h,b)})},this),this)}}return i.Event=j,i.EventEmitter=m,i.Listener=k,i.default=m,i}({});//# sourceMappingURL=api.js.map