@resk/core
Version:
An innovative TypeScript framework that empowers developers to build applications with a fully decorator-based architecture for efficient resource management. By combining the power of decorators with a resource-oriented design, DecorRes enhances code cla
1 lines • 2.14 kB
JavaScript
'use strict';const y=function(){let e={},l={},a=Array.prototype.slice;return {on:function(t,n){return n&&t&&(e[t]=e[t]||[]).push(n),{remove:()=>{this.off(t,n);}}},finally:function(t,n){return n&&t?((l[t]=l[t]||[]).push(n),this):this},off:function(t,n){if(!t)return this;if(t=="*"&&!n)e={};else if(n)for(var s=e[t],r=0,b;b=s&&s[r];++r)b==n&&s.splice(r--,1);return this},once:function(t,n){const s=(...r)=>{this.off(t,s),n.apply(this,r);};return this.on(t,s)},trigger:function(t,...n){if(!t)return this;let s,r,b,v=null;typeof n[n.length-1]=="function"&&(v=n.pop()),s=a.call(e[t]||[],0);let i=[];for(b=0;r=s[b];++b)typeof r=="function"&&i.push(r.apply(this,n));typeof e["*"]=="function"&&t!="*"&&(this.trigger(t,...n),this.trigger("*",...n));var f=a.call(l[t]||[],0);for(b=0;r=f[b];++b)r.call(this,i,n);return v&&v.call(this,i,n),this},offAll:function(){return e={},l={},this},getEventCallBacks:function(){return e}}},p=function(e){if(o(e))return e;const l=e||{},a=y();return Object.defineProperties(l,{_____isObservable:{value:true},on:{value:a.on.bind(l)},finally:{value:a.finally.bind(l)},off:{value:a.off.bind(l)},offAll:{value:a.offAll.bind(l)},once:{value:a.once.bind(l)},getEventCallBacks:{value:a.getEventCallBacks.bind(l)},trigger:{value:a.trigger.bind(l)}}),l};class c{constructor(){this._____isObservable=true;this._observable=y();}on(l,a){return this._observable.on.call(this,l,a)}finally(l,a){return this._observable.finally.call(this,l,a)}off(l,a){return this._observable.off.call(this,l,a)}trigger(l,...a){return this._observable.trigger.call(this,l,...a)}offAll(){return this._observable.offAll.call(this)}once(l,a){return this._observable.once.call(this,l,a)}getEventCallBacks(){return this._observable.getEventCallBacks.call(this)}}function o(e){if(!e||["string","boolean","number"].includes(typeof e))return false;try{return (e==null?void 0:e._____isObservable)===!0&&typeof(e==null?void 0:e.on)=="function"&&typeof(e==null?void 0:e.trigger)=="function"&&typeof(e==null?void 0:e.off)=="function"}catch(l){}return false}exports.ObservableClass=c;exports.isObservable=o;exports.observable=p;exports.observableFactory=y;