vue-act-master 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/vue-act-master.js +0 -1
- package/dist/vue-act-master.umd.cjs +1 -1
- package/package.json +1 -1
- package/src/index.ts +0 -1
package/dist/vue-act-master.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(c,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(c=typeof globalThis<"u"?globalThis:c||self,u(c["vue-act-master"]={}))})(this,function(c){"use strict";var W=Object.defineProperty;var x=(c,u,b)=>u in c?W(c,u,{enumerable:!0,configurable:!0,writable:!0,value:b}):c[u]=b;var O=(c,u,b)=>(x(c,typeof u!="symbol"?u+"":u,b),b);var u=Object.defineProperty,b=(e,t,s)=>t in e?u(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,o=(e,t,s)=>(b(e,typeof t!="symbol"?t+"":t,s),s);class d{constructor(t,s){if(o(this,"reason",""),o(this,"data"),typeof t=="string"){this.reason=t,this.data=s;return}if(t&&typeof t=="object")return Object.assign(t,{_name:this._name,reason:t.message||""})}static get _name(){return"__CancelledAct__"}get _name(){return d._name}static is(t){return!t||typeof t!="object"?!1:t._name===d._name}valueOf(){return null}toString(){return this.reason}}class A extends Error{constructor(t){super(`Can't find "${t}" action`),this.eventName=t}}class D extends Error{constructor(t){super(`Action "${t}" already existing`),this.eventName=t}}class v extends Error{constructor(t){super(`"${t}" already exists in DI`),this.key=t}}class $ extends Error{constructor(){super(`"di" can't be array`)}}const S="2.0.1";function k(e){return function(t,s){t._DI_MAP_||(t._DI_MAP_={}),t._DI_MAP_[s]=e}}function j(){return(e,t)=>{Object.defineProperty(e,"useEmit",{value:function(s){this[t]=s}})}}const y=class{constructor(e={}){if(o(this,"version",S),o(this,"_actions",new Map),o(this,"_watchers",new Map),o(this,"_listeners",new Map),o(this,"_inProgressWatchers",new Map),o(this,"_subsMap",new Map),o(this,"_lastUnsubscribe",()=>!1),o(this,"_DIContainer",{}),o(this,"_singlePromisesStore",new Map),o(this,"config",{errorOnReplaceDI:!1,autoUnsubscribeCallback:void 0,errorHandlerEventName:void 0}),o(this,"exec",async(i,...h)=>{if(this.setProgress(i,!0),this._singlePromisesStore.has(i)){const f=this._singlePromisesStore.get(i);if(f)return f}const _=this.emit(i,...h).then(f=>(this.setProgress(i,!1),f)).then(f=>(this._singlePromisesStore.has(i)&&this._singlePromisesStore.delete(i),f)).catch(f=>{if(this.setProgress(i,!1),f instanceof A)throw f;const P=this.getActionOrNull(i);if(P!=null&&P.errorHandlerEventName&&P.errorHandlerEventName!==i)return this.emit(P.errorHandlerEventName,f),new d(f);if(this.config.errorHandlerEventName&&this.config.errorHandlerEventName!==i)return this.emit(this.config.errorHandlerEventName,f),Promise.resolve(null);throw f}),m=this.getActionOrNull(i);return m&&m.isSingleExec&&this._singlePromisesStore.set(i,_),_}),o(this,"subscribe",(i,h,_)=>{this._listeners.set(i,[...this._listeners.get(i)||[],h]);const m=()=>this.unsubscribe(i,h);return this._lastUnsubscribe=m,this.config.autoUnsubscribeCallback&&this.config.autoUnsubscribeCallback({context:_,listener:h,eventName:i}),_&&this.subsList.add(_),m}),o(this,"once",(i,h)=>{const _=this.subscribe(i,(...m)=>{_(),h(...m)});return _}),o(this,"on",(i,h,_)=>this.subscribe(i,h,_)),y.instance)return y.instance;const{actions:t,di:s,errorOnReplaceDI:r,autoUnsubscribeCallback:n,errorHandlerEventName:l}=e;if(t&&this.addActions(t),typeof n=="function"&&(this.config.autoUnsubscribeCallback=n),typeof s=="object"&&s){if(Array.isArray(s))throw new $;for(const i in s)Object.prototype.hasOwnProperty.call(s,i)&&this.setDI(i,s[i])}typeof r=="boolean"&&(this.config.errorOnReplaceDI=r),typeof l=="string"&&(this.config.errorHandlerEventName=l),y.instance=this}static getInstance(){if(!y.instance)throw new Error("ActMaster not initialized");return y.instance}addActions(e){Array.isArray(e)&&e.forEach(t=>{this.addAction(t)})}addAction(e){const t=e.name;if(this._actions.has(t))throw new D(t);if(e.useEmit){const s=(r,...n)=>this.emit(r,...n);e.useEmit(s)}return this._actions.set(t,e),this.emitDIProps(e),e.watch&&e.watch.forEach(s=>{const r=this._watchers.get(s)||[];r.push(t),this._watchers.set(s,r)}),this}removeAction(e){if(!this._actions.has(e))throw new A(e);this._actions.delete(e)}clearActions(){this._actions.clear()}clearListeners(){for(const e in this._listeners)this._listeners.has(e)&&this._listeners.delete(e)}async emit(e,...t){const s=this.getActionOrNull(e);if(s===null)throw new A(e);if(s.validateInput){const n=await s.validateInput(...t);if(n!==!0)return this.config.errorHandlerEventName&&this.emit(this.config.errorHandlerEventName,n),n}const r=await s.exec(...t);if(r instanceof d||d.is(r))return r;if(this.notifyListeners(e,r),this._watchers.has(e))for(const n of this._watchers.get(e)||[])this.emit(n,r);return r}notifyListeners(e,t){const s=this._listeners.get(e);s&&s.forEach(r=>{r(t)})}unsubscribe(e,t){const s=this._listeners.get(e);if(!s)return this._subsMap.set(e,[]),!1;const r=s.indexOf(t);return r>-1&&s.splice(r,1),this._listeners.set(e,s),r>-1}off(e,t){return this.unsubscribe(e,t)}inProgress(e,t){if(Array.isArray(e)){e.forEach(n=>this._inProgressWatchers.set(n,t));const r=()=>{e.forEach(n=>{this._inProgressWatchers.delete(n)})};return this._lastUnsubscribe=r,r}this._inProgressWatchers.set(e,t);const s=()=>this._inProgressWatchers.delete(e);return this._lastUnsubscribe=s,s}setProgress(e,t){this._inProgressWatchers.has(e)&&this._inProgressWatchers.get(e)(t)}get subsList(){return{add:(e,...t)=>{t.length||t.push(this._lastUnsubscribe);const s=this._subsMap.get(e)||[];s.push(...t),this._subsMap.set(e,s)},clear:e=>{(this._subsMap.get(e)||[]).forEach(t=>t()),this._subsMap.delete(e)}}}clearDI(){this._DIContainer={}}setDI(e,t){if(this.config.errorOnReplaceDI&&this._DIContainer[e])throw new v(e);return this._DIContainer[e]=t,this.freshEmitDI(),this}freshEmitDI(){let e;Object.keys(this._actions).forEach(t=>{e=this._actions.get(t),e&&this.emitDIProps(e)})}emitDIProps(e){e._DI_CONTAINER_||Object.defineProperty(e,"_DI_CONTAINER_",{get:()=>this._DIContainer,enumerable:!1}),e._DI_MAP_&&Object.keys(e._DI_MAP_).forEach(t=>{var s;if(e[t])return;const r=(s=e._DI_MAP_)==null?void 0:s[t];r&&Object.defineProperty(e,t,{get(){return this._DI_CONTAINER_[r]},enumerable:!0})}),e.useDI&&e.useDI(this._DIContainer)}getActionOrNull(e){return this._actions.get(e)||null}};let g=y;o(g,"instance");const a=class{constructor(){}static getInstance(e={}){return a.resetAll(),a.removeSingleton(),a.$act=new g(e),a.$act}static resetAll(){a.$act&&(a.$act.clearActions(),a.$act.clearListeners(),a.$act.clearDI()),a._lastResult=void 0}static removeSingleton(){g.instance=void 0,a._lastResult=void 0}static addActions(e){a.$act.addActions(e)}static exec(e,...t){return a.$act.exec(e,...t).then(s=>(a._lastResult=s,s)).catch(s=>{throw a._lastResult=s,s})}static subscribe(e,t,s){return a.$act.subscribe(e,t,s)}static entityCount(e){if(e==="di")return Object.keys(a.$act._DIContainer).length;if(e==="actions")return a.$act._actions.size;const t={watchers:"_watchers",listeners:"_listeners"}[e];let s=0;return a.$act[t].forEach(r=>{s+=r.length}),s}static getLastResult(){return a._lastResult}static makeActionStub(e){return{name:`Act_${Math.random()}`,exec:()=>null,...e}}};let p=a;o(p,"$act"),o(p,"_lastResult"),I.init=e=>new g(e);const R=(e,t,s)=>{const r=I().subscribe(e,t);return s&&(typeof s=="function"?s(r):I().subsList.add(s,r)),r},M=e=>I().subsList.clear(e);I.subListClear=M;function I(){const e=g.getInstance();if(!e)throw new Error('Instance call before initialization. Make a "new ActMaster()" first');return e}const C=e=>{if(typeof e!="function"||!e.name)throw new Error(`Pass not valid function: "${e}"`);return{name:e.name,exec:e}},H=C;function N(e){return(t,s,r)=>{const n=typeof t=="function"?t:t.constructor;n.__decorators__||(n.__decorators__=[]),typeof r!="number"&&(r=void 0),n.__decorators__.push(l=>e(l,s,r))}}function U(e,t,s=null){return N((r,n)=>{const l={created(){this.$act.subscribe(e,i=>{const h=L(i,t,s);typeof this[n]=="function"?this[n](h):this[n]=h},this)}};r.mixins?r.mixins=[...r.mixins,l]:r.mixins=[l]})}function L(e,t,s){if(e===void 0)return s;if(typeof t=="function")return t(e);let r=e;if(t){const n=(t||"").split(".");let l,i=0;for(i=0;i<n.length&&r;i++)l=n[i],r=r[l]}return r===void 0?s:r}function T(e){return N((t,s)=>{const r={created(){const n=this.$act.inProgress(e,l=>{this[s]=l});this.$once("hook:beforeDestroy",()=>{n(e)})}};t.mixins?t.mixins=[...t.mixins,r]:t.mixins=[r]})}const E=class{static install(t,s){var n;
|
|
1
|
+
(function(c,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(c=typeof globalThis<"u"?globalThis:c||self,u(c["vue-act-master"]={}))})(this,function(c){"use strict";var W=Object.defineProperty;var x=(c,u,b)=>u in c?W(c,u,{enumerable:!0,configurable:!0,writable:!0,value:b}):c[u]=b;var O=(c,u,b)=>(x(c,typeof u!="symbol"?u+"":u,b),b);var u=Object.defineProperty,b=(e,t,s)=>t in e?u(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,o=(e,t,s)=>(b(e,typeof t!="symbol"?t+"":t,s),s);class d{constructor(t,s){if(o(this,"reason",""),o(this,"data"),typeof t=="string"){this.reason=t,this.data=s;return}if(t&&typeof t=="object")return Object.assign(t,{_name:this._name,reason:t.message||""})}static get _name(){return"__CancelledAct__"}get _name(){return d._name}static is(t){return!t||typeof t!="object"?!1:t._name===d._name}valueOf(){return null}toString(){return this.reason}}class A extends Error{constructor(t){super(`Can't find "${t}" action`),this.eventName=t}}class D extends Error{constructor(t){super(`Action "${t}" already existing`),this.eventName=t}}class v extends Error{constructor(t){super(`"${t}" already exists in DI`),this.key=t}}class $ extends Error{constructor(){super(`"di" can't be array`)}}const S="2.0.1";function k(e){return function(t,s){t._DI_MAP_||(t._DI_MAP_={}),t._DI_MAP_[s]=e}}function j(){return(e,t)=>{Object.defineProperty(e,"useEmit",{value:function(s){this[t]=s}})}}const y=class{constructor(e={}){if(o(this,"version",S),o(this,"_actions",new Map),o(this,"_watchers",new Map),o(this,"_listeners",new Map),o(this,"_inProgressWatchers",new Map),o(this,"_subsMap",new Map),o(this,"_lastUnsubscribe",()=>!1),o(this,"_DIContainer",{}),o(this,"_singlePromisesStore",new Map),o(this,"config",{errorOnReplaceDI:!1,autoUnsubscribeCallback:void 0,errorHandlerEventName:void 0}),o(this,"exec",async(i,...h)=>{if(this.setProgress(i,!0),this._singlePromisesStore.has(i)){const f=this._singlePromisesStore.get(i);if(f)return f}const _=this.emit(i,...h).then(f=>(this.setProgress(i,!1),f)).then(f=>(this._singlePromisesStore.has(i)&&this._singlePromisesStore.delete(i),f)).catch(f=>{if(this.setProgress(i,!1),f instanceof A)throw f;const P=this.getActionOrNull(i);if(P!=null&&P.errorHandlerEventName&&P.errorHandlerEventName!==i)return this.emit(P.errorHandlerEventName,f),new d(f);if(this.config.errorHandlerEventName&&this.config.errorHandlerEventName!==i)return this.emit(this.config.errorHandlerEventName,f),Promise.resolve(null);throw f}),m=this.getActionOrNull(i);return m&&m.isSingleExec&&this._singlePromisesStore.set(i,_),_}),o(this,"subscribe",(i,h,_)=>{this._listeners.set(i,[...this._listeners.get(i)||[],h]);const m=()=>this.unsubscribe(i,h);return this._lastUnsubscribe=m,this.config.autoUnsubscribeCallback&&this.config.autoUnsubscribeCallback({context:_,listener:h,eventName:i}),_&&this.subsList.add(_),m}),o(this,"once",(i,h)=>{const _=this.subscribe(i,(...m)=>{_(),h(...m)});return _}),o(this,"on",(i,h,_)=>this.subscribe(i,h,_)),y.instance)return y.instance;const{actions:t,di:s,errorOnReplaceDI:r,autoUnsubscribeCallback:n,errorHandlerEventName:l}=e;if(t&&this.addActions(t),typeof n=="function"&&(this.config.autoUnsubscribeCallback=n),typeof s=="object"&&s){if(Array.isArray(s))throw new $;for(const i in s)Object.prototype.hasOwnProperty.call(s,i)&&this.setDI(i,s[i])}typeof r=="boolean"&&(this.config.errorOnReplaceDI=r),typeof l=="string"&&(this.config.errorHandlerEventName=l),y.instance=this}static getInstance(){if(!y.instance)throw new Error("ActMaster not initialized");return y.instance}addActions(e){Array.isArray(e)&&e.forEach(t=>{this.addAction(t)})}addAction(e){const t=e.name;if(this._actions.has(t))throw new D(t);if(e.useEmit){const s=(r,...n)=>this.emit(r,...n);e.useEmit(s)}return this._actions.set(t,e),this.emitDIProps(e),e.watch&&e.watch.forEach(s=>{const r=this._watchers.get(s)||[];r.push(t),this._watchers.set(s,r)}),this}removeAction(e){if(!this._actions.has(e))throw new A(e);this._actions.delete(e)}clearActions(){this._actions.clear()}clearListeners(){for(const e in this._listeners)this._listeners.has(e)&&this._listeners.delete(e)}async emit(e,...t){const s=this.getActionOrNull(e);if(s===null)throw new A(e);if(s.validateInput){const n=await s.validateInput(...t);if(n!==!0)return this.config.errorHandlerEventName&&this.emit(this.config.errorHandlerEventName,n),n}const r=await s.exec(...t);if(r instanceof d||d.is(r))return r;if(this.notifyListeners(e,r),this._watchers.has(e))for(const n of this._watchers.get(e)||[])this.emit(n,r);return r}notifyListeners(e,t){const s=this._listeners.get(e);s&&s.forEach(r=>{r(t)})}unsubscribe(e,t){const s=this._listeners.get(e);if(!s)return this._subsMap.set(e,[]),!1;const r=s.indexOf(t);return r>-1&&s.splice(r,1),this._listeners.set(e,s),r>-1}off(e,t){return this.unsubscribe(e,t)}inProgress(e,t){if(Array.isArray(e)){e.forEach(n=>this._inProgressWatchers.set(n,t));const r=()=>{e.forEach(n=>{this._inProgressWatchers.delete(n)})};return this._lastUnsubscribe=r,r}this._inProgressWatchers.set(e,t);const s=()=>this._inProgressWatchers.delete(e);return this._lastUnsubscribe=s,s}setProgress(e,t){this._inProgressWatchers.has(e)&&this._inProgressWatchers.get(e)(t)}get subsList(){return{add:(e,...t)=>{t.length||t.push(this._lastUnsubscribe);const s=this._subsMap.get(e)||[];s.push(...t),this._subsMap.set(e,s)},clear:e=>{(this._subsMap.get(e)||[]).forEach(t=>t()),this._subsMap.delete(e)}}}clearDI(){this._DIContainer={}}setDI(e,t){if(this.config.errorOnReplaceDI&&this._DIContainer[e])throw new v(e);return this._DIContainer[e]=t,this.freshEmitDI(),this}freshEmitDI(){let e;Object.keys(this._actions).forEach(t=>{e=this._actions.get(t),e&&this.emitDIProps(e)})}emitDIProps(e){e._DI_CONTAINER_||Object.defineProperty(e,"_DI_CONTAINER_",{get:()=>this._DIContainer,enumerable:!1}),e._DI_MAP_&&Object.keys(e._DI_MAP_).forEach(t=>{var s;if(e[t])return;const r=(s=e._DI_MAP_)==null?void 0:s[t];r&&Object.defineProperty(e,t,{get(){return this._DI_CONTAINER_[r]},enumerable:!0})}),e.useDI&&e.useDI(this._DIContainer)}getActionOrNull(e){return this._actions.get(e)||null}};let g=y;o(g,"instance");const a=class{constructor(){}static getInstance(e={}){return a.resetAll(),a.removeSingleton(),a.$act=new g(e),a.$act}static resetAll(){a.$act&&(a.$act.clearActions(),a.$act.clearListeners(),a.$act.clearDI()),a._lastResult=void 0}static removeSingleton(){g.instance=void 0,a._lastResult=void 0}static addActions(e){a.$act.addActions(e)}static exec(e,...t){return a.$act.exec(e,...t).then(s=>(a._lastResult=s,s)).catch(s=>{throw a._lastResult=s,s})}static subscribe(e,t,s){return a.$act.subscribe(e,t,s)}static entityCount(e){if(e==="di")return Object.keys(a.$act._DIContainer).length;if(e==="actions")return a.$act._actions.size;const t={watchers:"_watchers",listeners:"_listeners"}[e];let s=0;return a.$act[t].forEach(r=>{s+=r.length}),s}static getLastResult(){return a._lastResult}static makeActionStub(e){return{name:`Act_${Math.random()}`,exec:()=>null,...e}}};let p=a;o(p,"$act"),o(p,"_lastResult"),I.init=e=>new g(e);const R=(e,t,s)=>{const r=I().subscribe(e,t);return s&&(typeof s=="function"?s(r):I().subsList.add(s,r)),r},M=e=>I().subsList.clear(e);I.subListClear=M;function I(){const e=g.getInstance();if(!e)throw new Error('Instance call before initialization. Make a "new ActMaster()" first');return e}const C=e=>{if(typeof e!="function"||!e.name)throw new Error(`Pass not valid function: "${e}"`);return{name:e.name,exec:e}},H=C;function N(e){return(t,s,r)=>{const n=typeof t=="function"?t:t.constructor;n.__decorators__||(n.__decorators__=[]),typeof r!="number"&&(r=void 0),n.__decorators__.push(l=>e(l,s,r))}}function U(e,t,s=null){return N((r,n)=>{const l={created(){this.$act.subscribe(e,i=>{const h=L(i,t,s);typeof this[n]=="function"?this[n](h):this[n]=h},this)}};r.mixins?r.mixins=[...r.mixins,l]:r.mixins=[l]})}function L(e,t,s){if(e===void 0)return s;if(typeof t=="function")return t(e);let r=e;if(t){const n=(t||"").split(".");let l,i=0;for(i=0;i<n.length&&r;i++)l=n[i],r=r[l]}return r===void 0?s:r}function T(e){return N((t,s)=>{const r={created(){const n=this.$act.inProgress(e,l=>{this[s]=l});this.$once("hook:beforeDestroy",()=>{n(e)})}};t.mixins?t.mixins=[...t.mixins,r]:t.mixins=[r]})}const E=class{static install(t,s){var n;const r=new g({autoUnsubscribeCallback({context:l,eventName:i,listener:h}){l&&typeof l=="function"?l(function(){r.unsubscribe(i,h)}):l&&typeof l.$once=="function"&&l.$once("hook:beforeDestroy",()=>{r.unsubscribe(i,h)})},...s});E.instance=r,(n=t.config)!=null&&n.globalProperties&&!t.config.globalProperties.$act?(t.config.globalProperties.$act=r,t.provide("$act",r)):Object.prototype.hasOwnProperty.call(t,"$act")||(t.act=r,t.prototype.$act=r)}install(t,s){E.install(t,s)}};let w=E;O(w,"instance",null),c.ActInProgress=T,c.ActMaster=g,c.ActSubscribe=U,c.ActTest=p,c.ActinonAlreadyExistingError=D,c.CancelledAct=d,c.Emit=j,c.InvalidDITypeError=$,c.KeyAlreadyExistsInDIError=v,c.NotFoundActionError=A,c.UseDI=k,c.VueActMaster=w,c.act=I,c.actSubscribe=R,c.fn2act=H,c.functionToAction=C,c.subListClear=M,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -36,7 +36,6 @@ export class VueActMaster {
|
|
|
36
36
|
static instance: ActMaster | null = null;
|
|
37
37
|
|
|
38
38
|
static install(vue: any, options?: ActMasterOptions): void {
|
|
39
|
-
debugger;
|
|
40
39
|
const actMaster = new ActMaster({
|
|
41
40
|
autoUnsubscribeCallback({ context, eventName, listener }) {
|
|
42
41
|
if (context && typeof context === 'function') {
|