UNPKG

@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.6 kB
'use strict';var T=Object.defineProperty,I=Object.defineProperties;var h=Object.getOwnPropertyDescriptors;var y=Object.getOwnPropertySymbols;var g=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable;var f=(t,e,l)=>e in t?T(t,e,{enumerable:true,configurable:true,writable:true,value:l}):t[e]=l,p=(t,e)=>{for(var l in e||(e={}))g.call(e,l)&&f(t,l,e[l]);if(y)for(var l of y(e))C.call(e,l)&&f(t,l,e[l]);return t},c=(t,e)=>I(t,h(e));var E=function(t){let e={},l={},o=Array.prototype.slice;return c(p({},Object.assign({},t)),{on:function(n,a){return a&&n&&(e[n]=e[n]||[]).push(a),{remove:()=>{this.off(n,a);}}},finally:function(n,a){return a&&n?((l[n]=l[n]||[]).push(a),this):this},off:function(n,a){if(!n)return this;if(n=="*"&&!a)e={};else if(a)for(var s=e[n],r=0,b;b=s&&s[r];++r)b==a&&s.splice(r--,1);return this},once:function(n,a){let s=(...r)=>{this.off(n,s),a.apply(this,r);};return this.on(n,s)},trigger:function(n,...a){if(!n)return this;let s,r,b,v=null;typeof a[a.length-1]=="function"&&(v=a.pop()),s=o.call(e[n]||[],0);let i=[];for(b=0;r=s[b];++b)typeof r=="function"&&i.push(r.apply(this,a));typeof e["*"]=="function"&&n!="*"&&(this.trigger(n,...a),this.trigger("*",...a));var O=o.call(l[n]||[],0);for(b=0;r=O[b];++b)r.call(this,i,a);return v&&v.call(this,i,a),this},offAll:function(){return e={},l={},this},getEventCallBacks:function(){return e}})},d=function(t){if(k(t))return t;let e=t||{},l=E();return Object.defineProperties(e,{_____isObservable:{value:true},on:{value:l.on.bind(e)},finally:{value:l.finally.bind(e)},off:{value:l.off.bind(e)},offAll:{value:l.offAll.bind(e)},once:{value:l.once.bind(e)},getEventCallBacks:{value:l.getEventCallBacks.bind(e)},trigger:{value:l.trigger.bind(e)}}),e},u=class{constructor(){this._____isObservable=true;this._observable=E();}on(e,l){return this._observable.on.call(this,e,l)}finally(e,l){return this._observable.finally.call(this,e,l)}off(e,l){return this._observable.off.call(this,e,l)}trigger(e,...l){return this._observable.trigger.call(this,e,...l)}offAll(){return this._observable.offAll.call(this)}once(e,l){return this._observable.once.call(this,e,l)}getEventCallBacks(){return this._observable.getEventCallBacks.call(this)}};function k(t){if(!t||["string","boolean","number"].includes(typeof t))return false;try{return (t==null?void 0:t._____isObservable)===!0&&typeof(t==null?void 0:t.on)=="function"&&typeof(t==null?void 0:t.trigger)=="function"&&typeof(t==null?void 0:t.off)=="function"}catch(e){}return false}exports.ObservableClass=u;exports.isObservable=k;exports.observable=d;exports.observableFactory=E;