UNPKG

conciseee

Version:

Concise (409B) Event Emitter with features like async notification, regex based event matching and universal handlers

1 lines 838 B
function ee(){let b={"*":[]},c=[];return{emit(a,...d){return b[a]?b[a].forEach(a=>a.t?"function"==typeof a.t?a.t(()=>a.f(...d)):setTimeout(()=>a.f(...d),a.t):a(...d)):0,c.forEach(b=>null==a.match(b.p)?0:b.f.t?"function"==typeof b.f.t?b.f.t(()=>b.f.f(...d)):setTimeout(()=>b.f.f(...d),b.f.t):b.f(...d)),"*"==a?0:b["*"].forEach(b=>b.t?"function"==typeof b.t?b.t(()=>b.f(a,...d)):setTimeout(()=>b.f(a,...d),b.t):b(a,...d)),this},on(d,e,g){return g?e={f:e,t:g?g:0}:0,d instanceof RegExp?c.push({p:d,f:e}):b[d]?e=b[d].push(e):(b[d]=[]).push(e),this},off(a,d){let e;return a instanceof RegExp?c.forEach(b=>a.toString()==b.p.toString()&&d==b.f||null!=b.t&&d==b.f?e=b:0)||e?delete c[c.indexOf(e)]:0:b[a]?b[a].forEach(a=>d==a||null!=a.f.t&&d==a.f.f?e=a:0)||e?delete b[a][b[a].indexOf(e)]:0:0,this}}}"undefined"!=typeof module&&(module.exports=ee);