@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
JavaScript
'use strict';var O=Object.defineProperty,T=Object.defineProperties;var I=Object.getOwnPropertyDescriptors;var y=Object.getOwnPropertySymbols;var h=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable;var f=(t,e,l)=>e in t?O(t,e,{enumerable:true,configurable:true,writable:true,value:l}):t[e]=l,p=(t,e)=>{for(var l in e||(e={}))h.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)=>T(t,I(e));const u=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){const 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 E=o.call(l[n]||[],0);for(b=0;r=E[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}})},_=function(t){if(g(t))return t;const e=t||{},l=u();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};class d{constructor(){this._____isObservable=true;this._observable=u();}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 g(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=d;exports.isObservable=g;exports.observable=_;exports.observableFactory=u;