vue-act-master 2.1.1 → 2.1.2
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
CHANGED
|
@@ -50,7 +50,7 @@ class C extends Error {
|
|
|
50
50
|
super(`"di" can't be array`);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
const O = "2.1.
|
|
53
|
+
const O = "2.1.2";
|
|
54
54
|
function S(i) {
|
|
55
55
|
return function(e, t) {
|
|
56
56
|
e._DI_MAP_ || (e._DI_MAP_ = {}), e._DI_MAP_[t] = i;
|
|
@@ -77,10 +77,7 @@ const w = class b {
|
|
|
77
77
|
if (m)
|
|
78
78
|
return m;
|
|
79
79
|
}
|
|
80
|
-
const h = this.emit(n, ...u).catch((m) => {
|
|
81
|
-
debugger;
|
|
82
|
-
return this.catchEmitException(m, n);
|
|
83
|
-
}).finally(() => {
|
|
80
|
+
const h = this.emit(n, ...u).catch((m) => this.catchEmitException(m, n)).finally(() => {
|
|
84
81
|
this._singlePromisesStore.has(n) && this._singlePromisesStore.delete(n), this.setProgress(n, !1);
|
|
85
82
|
}), f = this.getActionOrNull(n);
|
|
86
83
|
return f && f.isSingleExec && this._singlePromisesStore.set(n, h), h;
|
|
@@ -177,12 +174,11 @@ const w = class b {
|
|
|
177
174
|
}
|
|
178
175
|
notifyListeners(e, t) {
|
|
179
176
|
const s = this._listeners.get(e);
|
|
180
|
-
if (
|
|
177
|
+
if (s && s.forEach((r) => {
|
|
178
|
+
r(t);
|
|
179
|
+
}), this._watchers.has(e))
|
|
181
180
|
for (const r of this._watchers.get(e) || [])
|
|
182
181
|
this.exec(r, t);
|
|
183
|
-
s && s.forEach((r) => {
|
|
184
|
-
r(t);
|
|
185
|
-
});
|
|
186
182
|
}
|
|
187
183
|
unsubscribe(e, t) {
|
|
188
184
|
const s = this._listeners.get(e);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(c,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(c=typeof globalThis<"u"?globalThis:c||self,h(c["vue-act-master"]={}))})(this,function(c){"use strict";var z=Object.defineProperty;var F=(c,h,d)=>h in c?z(c,h,{enumerable:!0,configurable:!0,writable:!0,value:d}):c[h]=d;var O=(c,h,d)=>(F(c,typeof h!="symbol"?h+"":h,d),d);var h=Object.defineProperty,d=(i,e,s)=>e in i?h(i,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):i[e]=s,l=(i,e,s)=>(d(i,typeof e!="symbol"?e+"":e,s),s);class g{constructor(e,s){if(l(this,"reason",""),l(this,"data"),typeof e=="string"){this.reason=e,this.data=s;return}if(e&&typeof e=="object")return Object.assign(e,{_name:this._name,reason:e.message||""})}static get _name(){return"__CancelledAct__"}get _name(){return g._name}static is(e){return!e||typeof e!="object"?!1:e._name===g._name}valueOf(){return null}toString(){return this.reason}}class I extends Error{constructor(e){super(`Can't find "${e}" action`),this.eventName=e}}class v extends Error{constructor(e){super(`Action "${e}" already existing`),this.eventName=e}}class D extends Error{constructor(e){super(`"${e}" already exists in DI`),this.key=e}}class $ extends Error{constructor(){super(`"di" can't be array`)}}const S="2.1.
|
|
1
|
+
(function(c,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(c=typeof globalThis<"u"?globalThis:c||self,h(c["vue-act-master"]={}))})(this,function(c){"use strict";var z=Object.defineProperty;var F=(c,h,d)=>h in c?z(c,h,{enumerable:!0,configurable:!0,writable:!0,value:d}):c[h]=d;var O=(c,h,d)=>(F(c,typeof h!="symbol"?h+"":h,d),d);var h=Object.defineProperty,d=(i,e,s)=>e in i?h(i,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):i[e]=s,l=(i,e,s)=>(d(i,typeof e!="symbol"?e+"":e,s),s);class g{constructor(e,s){if(l(this,"reason",""),l(this,"data"),typeof e=="string"){this.reason=e,this.data=s;return}if(e&&typeof e=="object")return Object.assign(e,{_name:this._name,reason:e.message||""})}static get _name(){return"__CancelledAct__"}get _name(){return g._name}static is(e){return!e||typeof e!="object"?!1:e._name===g._name}valueOf(){return null}toString(){return this.reason}}class I extends Error{constructor(e){super(`Can't find "${e}" action`),this.eventName=e}}class v extends Error{constructor(e){super(`Action "${e}" already existing`),this.eventName=e}}class D extends Error{constructor(e){super(`"${e}" already exists in DI`),this.key=e}}class $ extends Error{constructor(){super(`"di" can't be array`)}}const S="2.1.2";function j(i){return function(e,s){e._DI_MAP_||(e._DI_MAP_={}),e._DI_MAP_[s]=i}}function k(){return(i,e)=>{Object.defineProperty(i,"useEmit",{value:function(s){this[e]=s}})}}const M=class E{constructor(e={}){if(l(this,"version",S),l(this,"_actions",new Map),l(this,"_watchers",new Map),l(this,"_listeners",new Map),l(this,"_inProgressWatchers",new Map),l(this,"_subsMap",new Map),l(this,"_lastUnsubscribe",()=>!1),l(this,"_DIContainer",{}),l(this,"_singlePromisesStore",new Map),l(this,"config",{errorOnReplaceDI:!1,autoUnsubscribeCallback:void 0,errorHandlerEventName:void 0}),l(this,"exec",async(n,...b)=>{if(this.setProgress(n,!0),this._singlePromisesStore.has(n)){const P=this._singlePromisesStore.get(n);if(P)return P}const f=this.emit(n,...b).catch(P=>this.catchEmitException(P,n)).finally(()=>{this._singlePromisesStore.has(n)&&this._singlePromisesStore.delete(n),this.setProgress(n,!1)}),_=this.getActionOrNull(n);return _&&_.isSingleExec&&this._singlePromisesStore.set(n,f),f}),l(this,"subscribe",(n,b,f)=>{this._listeners.set(n,[...this._listeners.get(n)||[],b]);const _=()=>this.unsubscribe(n,b);return this._lastUnsubscribe=_,this.config.autoUnsubscribeCallback&&this.config.autoUnsubscribeCallback({context:f,listener:b,eventName:n}),f&&this.subsList.add(f),_}),l(this,"once",(n,b)=>{const f=this.subscribe(n,(..._)=>{f(),b(..._)});return f}),l(this,"on",(n,b,f)=>this.subscribe(n,b,f)),E.instance)return E.instance;const{actions:s,di:t,errorOnReplaceDI:r,autoUnsubscribeCallback:a,errorHandlerEventName:u}=e;if(s&&this.addActions(s),typeof a=="function"&&(this.config.autoUnsubscribeCallback=a),typeof t=="object"&&t){if(Array.isArray(t))throw new $;for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&this.setDI(n,t[n])}typeof r=="boolean"&&(this.config.errorOnReplaceDI=r),typeof u=="string"&&(this.config.errorHandlerEventName=u),E.instance=this}static getInstance(){if(!E.instance)throw new Error("ActMaster not initialized");return E.instance}addActions(e){Array.isArray(e)&&e.forEach(s=>{this.addAction(s)})}addAction(e){const s=e.name;if(this._actions.has(s))throw new v(s);if(e.useEmit){const t=(r,...a)=>this.exec(r,...a);e.useEmit(t)}return this._actions.set(s,e),this.emitDIProps(e),e.watch&&e.watch.forEach(t=>{const r=this._watchers.get(t)||[];r.push(s),this._watchers.set(t,r)}),this}removeAction(e){if(!this._actions.has(e))throw new I(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,...s){const t=this.getActionOrNull(e);if(t===null)throw new I(e);if(t.validateInput){const r=await t.validateInput(...s);if(r!==!0)return this.config.errorHandlerEventName&&this.emit(this.config.errorHandlerEventName,r),t.errorHandlerEventName&&this.emit(t.errorHandlerEventName,r),r}try{const r=await t.exec(...s);return r instanceof g||g.is(r)||this.notifyListeners(e,r),r}catch(r){return this.catchEmitException(r,e)}}catchEmitException(e,s){if(e instanceof I)throw e;const t=this.getActionOrNull(s);return t!=null&&t.errorHandlerEventName&&t.errorHandlerEventName!==s?(this.emit(t.errorHandlerEventName,e),Promise.resolve(null)):this.config.errorHandlerEventName&&this.config.errorHandlerEventName!==s?(this.emit(this.config.errorHandlerEventName,e),Promise.resolve(null)):Promise.reject(e)}notifyListeners(e,s){const t=this._listeners.get(e);if(t&&t.forEach(r=>{r(s)}),this._watchers.has(e))for(const r of this._watchers.get(e)||[])this.exec(r,s)}unsubscribe(e,s){const t=this._listeners.get(e);if(!t)return this._subsMap.set(e,[]),!1;const r=t.indexOf(s);return r>-1&&t.splice(r,1),this._listeners.set(e,t),r>-1}off(e,s){return this.unsubscribe(e,s)}inProgress(e,s){if(Array.isArray(e)){e.forEach(a=>this._inProgressWatchers.set(a,s));const r=()=>{e.forEach(a=>{this._inProgressWatchers.delete(a)})};return this._lastUnsubscribe=r,r}this._inProgressWatchers.set(e,s);const t=()=>this._inProgressWatchers.delete(e);return this._lastUnsubscribe=t,t}setProgress(e,s){this._inProgressWatchers.has(e)&&this._inProgressWatchers.get(e)(s)}get subsList(){return{add:(e,...s)=>{s.length||s.push(this._lastUnsubscribe);const t=this._subsMap.get(e)||[];t.push(...s),this._subsMap.set(e,t)},clear:e=>{(this._subsMap.get(e)||[]).forEach(s=>s()),this._subsMap.delete(e)}}}clearDI(){this._DIContainer={}}setDI(e,s){if(this.config.errorOnReplaceDI&&this._DIContainer[e])throw new D(e);return this._DIContainer[e]=s,this.freshEmitDI(),this}freshEmitDI(){let e;Object.keys(this._actions).forEach(s=>{e=this._actions.get(s),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(s=>{var t;if(e[s])return;const r=(t=e._DI_MAP_)==null?void 0:t[s];r&&Object.defineProperty(e,s,{get(){return this._DI_CONTAINER_[r]},enumerable:!0})}),e.useDI&&e.useDI(this._DIContainer)}getActionOrNull(e){return this._actions.get(e)||null}};l(M,"instance");let m=M;const w=class o{constructor(){}static getInstance(e={}){return o.resetAll(),o.removeSingleton(),o.$act=new m(e),o.$act}static resetAll(){o.$act&&(o.$act.clearActions(),o.$act.clearListeners(),o.$act.clearDI()),o._lastResult=void 0}static removeSingleton(){m.instance=void 0,o._lastResult=void 0}static addActions(e){o.$act.addActions(e)}static exec(e,...s){return o.$act.exec(e,...s).then(t=>(o._lastResult=t,t)).catch(t=>{throw o._lastResult=t,t})}static subscribe(e,s,t){return o.$act.subscribe(e,s,t)}static entityCount(e){if(e==="di")return Object.keys(o.$act._DIContainer).length;if(e==="actions")return o.$act._actions.size;const s={watchers:"_watchers",listeners:"_listeners"}[e];let t=0;return o.$act[s].forEach(r=>{t+=r.length}),t}static getLastResult(){return o._lastResult}static makeActionStub(e){return{name:`Act_${Math.random()}`,exec:()=>null,...e}}};l(w,"$act"),l(w,"_lastResult");let H=w;function y(){const i=m.getInstance();if(!i)throw new Error('Instance call before initialization. Make a "new ActMaster()" first');return i}y.init=i=>new m(i);const R=(i,e,s)=>{const t=y().subscribe(i,e);return s&&(typeof s=="function"?s(t):y().subsList.add(s,t)),t},U=i=>y().subsList.clear(i);y.subListClear=U;const N=i=>{if(typeof i!="function"||!i.name)throw new Error(`Pass not valid function: "${i}"`);return{name:i.name,exec:i}},x=N;function C(i){return(e,s,t)=>{const r=typeof e=="function"?e:e.constructor;r.__decorators__||(r.__decorators__=[]),typeof t!="number"&&(t=void 0),r.__decorators__.push(a=>i(a,s,t))}}function L(i,e,s=null){return C((t,r)=>{const a={created(){this.$act.subscribe(i,u=>{const n=T(u,e,s);typeof this[r]=="function"?this[r](n):this[r]=n},this)}};t.mixins?t.mixins=[...t.mixins,a]:t.mixins=[a]})}function T(i,e,s){if(i===void 0)return s;if(typeof e=="function")return e(i);let t=i;if(e){const r=(e||"").split(".");let a,u=0;for(u=0;u<r.length&&t;u++)a=r[u],t=t[a]}return t===void 0?s:t}function W(i){return C((e,s)=>{const t={created(){const r=this.$act.inProgress(i,a=>{this[s]=a});this.$once("hook:beforeDestroy",()=>{r(i)})}};e.mixins?e.mixins=[...e.mixins,t]:e.mixins=[t]})}const p=class{static install(e,s){var r;const t=new m({autoUnsubscribeCallback({context:a,eventName:u,listener:n}){a&&typeof a=="function"?a(function(){t.unsubscribe(u,n)}):a&&typeof a.$once=="function"&&a.$once("hook:beforeDestroy",()=>{t.unsubscribe(u,n)})},...s});p.instance=t,(r=e.config)!=null&&r.globalProperties&&!e.config.globalProperties.$act?(e.config.globalProperties.$act=t,e.provide("$act",t)):Object.prototype.hasOwnProperty.call(e,"$act")||(e.act=t,e.prototype.$act=t)}install(e,s){p.install(e,s)}};let A=p;O(A,"instance",null),c.ActInProgress=W,c.ActMaster=m,c.ActSubscribe=L,c.ActTest=H,c.ActinonAlreadyExistingError=v,c.CancelledAct=g,c.Emit=k,c.InvalidDITypeError=$,c.KeyAlreadyExistsInDIError=D,c.NotFoundActionError=I,c.UseDI=j,c.VueActMaster=A,c.act=y,c.actSubscribe=R,c.fn2act=x,c.functionToAction=N,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-act-master",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "avil13",
|
|
6
6
|
"main": "dist/vue-act-master.umd.cjs",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
},
|
|
53
53
|
"license": "MIT",
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"act-master": "^2.1.
|
|
55
|
+
"act-master": "^2.1.2"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"act-master": "^2.1.
|
|
58
|
+
"act-master": "^2.1.2"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@babel/types": "^7.22.5",
|