vue-act-master 2.2.0 → 2.3.6

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.
@@ -1,27 +1,27 @@
1
1
  var D = Object.defineProperty;
2
- var v = (i, e, s) => e in i ? D(i, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : i[e] = s;
3
- var I = (i, e, s) => (v(i, typeof e != "symbol" ? e + "" : e, s), s);
4
- var $ = Object.defineProperty, x = (i, e, s) => e in i ? $(i, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : i[e] = s, c = (i, e, s) => (x(i, typeof e != "symbol" ? e + "" : e, s), s);
5
- class d {
6
- constructor(e, s) {
7
- if (c(this, "reason", ""), c(this, "data"), typeof e == "string") {
8
- this.reason = e, this.data = s;
2
+ var C = (r, t, e) => t in r ? D(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
+ var $ = (r, t, e) => (C(r, typeof t != "symbol" ? t + "" : t, e), e);
4
+ var N = Object.defineProperty, x = (r, t, e) => t in r ? N(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e, c = (r, t, e) => (x(r, typeof t != "symbol" ? t + "" : t, e), e);
5
+ let w = class y {
6
+ constructor(t, e) {
7
+ if (c(this, "reason", ""), c(this, "data"), typeof t == "string") {
8
+ this.reason = t, this.data = e;
9
9
  return;
10
10
  }
11
- if (e && typeof e == "object")
12
- return Object.assign(e, {
11
+ if (t && typeof t == "object")
12
+ return Object.assign(t, {
13
13
  _name: this._name,
14
- reason: e.message || ""
14
+ reason: t.message || ""
15
15
  });
16
16
  }
17
17
  static get _name() {
18
18
  return "__CancelledAct__";
19
19
  }
20
20
  get _name() {
21
- return d._name;
21
+ return y._name;
22
22
  }
23
- static is(e) {
24
- return !e || typeof e != "object" ? !1 : e._name === d._name;
23
+ static is(t) {
24
+ return !t || typeof t != "object" ? !1 : t._name === y._name;
25
25
  }
26
26
  valueOf() {
27
27
  return null;
@@ -29,91 +29,76 @@ class d {
29
29
  toString() {
30
30
  return this.reason;
31
31
  }
32
- }
33
- class E extends Error {
34
- constructor(e) {
35
- super(`Can't find "${e}" action`), this.eventName = e;
36
- }
37
- }
38
- class N extends Error {
39
- constructor(e) {
40
- super(`Action "${e}" already existing`), this.eventName = e;
32
+ };
33
+ class p extends Error {
34
+ constructor(t) {
35
+ super(`Can't find "${t}" action`), this.eventName = t;
41
36
  }
42
37
  }
43
38
  class M extends Error {
44
- constructor(e) {
45
- super(`"${e}" already exists in DI`), this.key = e;
39
+ constructor(t) {
40
+ super(`Action "${t}" already existing`), this.eventName = t;
46
41
  }
47
42
  }
48
- class C extends Error {
43
+ let O = class extends Error {
44
+ constructor(t) {
45
+ super(`"${t}" already exists in DI`), this.key = t;
46
+ }
47
+ }, S = class extends Error {
49
48
  constructor() {
50
49
  super(`"di" can't be array`);
51
50
  }
52
- }
53
- const O = "2.2.0";
54
- function S(i) {
55
- return function(e, s) {
56
- const t = e;
57
- t._DI_MAP_ || (t._DI_MAP_ = {}), t._DI_MAP_[s] = i;
58
- };
59
- }
60
- function U() {
61
- return (i, e) => {
62
- Object.defineProperty(i, "useEmit", {
63
- value: function(s) {
64
- this[e] = s;
65
- }
66
- });
67
- };
68
- }
69
- const w = class b {
70
- constructor(e = {}) {
71
- if (c(this, "version", O), c(this, "_actions", /* @__PURE__ */ new Map()), c(this, "_watchers", /* @__PURE__ */ new Map()), c(this, "_listeners", /* @__PURE__ */ new Map()), c(this, "_inProgressWatchers", /* @__PURE__ */ new Map()), c(this, "_subsMap", /* @__PURE__ */ new Map()), c(this, "_lastUnsubscribe", () => !1), c(this, "_DIContainer", {}), c(this, "_singlePromisesStore", /* @__PURE__ */ new Map()), c(this, "config", {
51
+ };
52
+ const k = "2.3.6", j = (r) => {
53
+ r.watch && !r.$watch && (r.$watch = r.watch), r.isSingleExec && typeof r.$isSingleton != "boolean" && (r.$isSingleton = r.isSingleExec), r.validateInput && !r.$validate && (r.$validate = r.validateInput), r.errorHandlerEventName && !r.$onError && (r.$onError = r.errorHandlerEventName);
54
+ }, P = class b {
55
+ constructor(t = {}) {
56
+ if (c(this, "version", k), c(this, "_actions", /* @__PURE__ */ new Map()), c(this, "_watchers", /* @__PURE__ */ new Map()), c(this, "_listeners", /* @__PURE__ */ new Map()), c(this, "_inProgressWatchers", /* @__PURE__ */ new Map()), c(this, "_subCurrentName", ""), c(this, "_subsMap", /* @__PURE__ */ new Map()), c(this, "_lastUnsubscribe", () => !1), c(this, "_DIContainer", {}), c(this, "_singlePromisesStore", /* @__PURE__ */ new Map()), c(this, "config", {
72
57
  errorOnReplaceDI: !1,
73
58
  autoUnsubscribeCallback: void 0,
74
59
  errorHandlerEventName: void 0
75
- }), c(this, "exec", async (n, ...u) => {
60
+ }), c(this, "exec", async (n, ...f) => {
76
61
  if (this.setProgress(n, !0), this._singlePromisesStore.has(n)) {
77
- const p = this._singlePromisesStore.get(n);
78
- if (p)
79
- return p;
62
+ const g = this._singlePromisesStore.get(n);
63
+ if (g)
64
+ return g;
80
65
  }
81
- const h = this.emit(n, ...u).catch((p) => this.catchEmitException(p, n)).finally(() => {
66
+ const l = this.emit(n, ...f).catch((g) => this.catchEmitException(g, n)).finally(() => {
82
67
  this._singlePromisesStore.has(n) && this._singlePromisesStore.delete(n), this.setProgress(n, !1);
83
- }), f = this.getActionOrNull(n);
84
- return f && f.isSingleExec && this._singlePromisesStore.set(n, h), h;
85
- }), c(this, "subscribe", (n, u, h) => {
68
+ }), u = this.getActionOrNull(n);
69
+ return u && u.$isSingleton && this._singlePromisesStore.set(n, l), l;
70
+ }), c(this, "subscribe", (n, f, l) => {
86
71
  this._listeners.set(n, [
87
72
  ...this._listeners.get(n) || [],
88
- u
73
+ f
89
74
  ]);
90
- const f = () => this.unsubscribe(n, u);
91
- return this._lastUnsubscribe = f, this.config.autoUnsubscribeCallback && this.config.autoUnsubscribeCallback({
92
- context: h,
93
- listener: u,
75
+ const u = () => this.unsubscribe(n, f);
76
+ return this._lastUnsubscribe = u, this.config.autoUnsubscribeCallback && this.config.autoUnsubscribeCallback({
77
+ context: l,
78
+ listener: f,
94
79
  eventName: n
95
- }), h && this.subsList.add(h), f;
96
- }), c(this, "once", (n, u) => {
97
- const h = this.subscribe(n, (...f) => {
98
- h(), u(...f);
80
+ }), l ? typeof l == "function" ? l(u) : this.subsList.add(l, u) : this._subCurrentName && this.subsList.add(this._subCurrentName, u), u;
81
+ }), c(this, "once", (n, f) => {
82
+ const l = this.subscribe(n, (...u) => {
83
+ l(), f(...u);
99
84
  });
100
- return h;
101
- }), c(this, "on", (n, u, h) => this.subscribe(n, u, h)), b.instance)
85
+ return l;
86
+ }), c(this, "on", (n, f, l) => this.subscribe(n, f, l)), b.instance)
102
87
  return b.instance;
103
88
  const {
104
- actions: s,
105
- di: t,
106
- errorOnReplaceDI: r,
89
+ actions: e,
90
+ di: s,
91
+ errorOnReplaceDI: i,
107
92
  autoUnsubscribeCallback: a,
108
- errorHandlerEventName: l
109
- } = e;
110
- if (s && this.addActions(s), typeof a == "function" && (this.config.autoUnsubscribeCallback = a), typeof t == "object" && t) {
111
- if (Array.isArray(t))
112
- throw new C();
113
- for (const n in t)
114
- Object.prototype.hasOwnProperty.call(t, n) && this.setDI(n, t[n]);
93
+ errorHandlerEventName: h
94
+ } = t;
95
+ if (e && this.addActions(e), typeof a == "function" && (this.config.autoUnsubscribeCallback = a), typeof s == "object" && s) {
96
+ if (Array.isArray(s))
97
+ throw new S();
98
+ for (const n in s)
99
+ Object.prototype.hasOwnProperty.call(s, n) && this.setDI(n, s[n]);
115
100
  }
116
- typeof r == "boolean" && (this.config.errorOnReplaceDI = r), typeof l == "string" && (this.config.errorHandlerEventName = l), b.instance = this;
101
+ typeof i == "boolean" && (this.config.errorOnReplaceDI = i), typeof h == "string" && (this.config.errorHandlerEventName = h), b.instance = this;
117
102
  }
118
103
  static getInstance() {
119
104
  if (!b.instance)
@@ -121,105 +106,117 @@ const w = class b {
121
106
  return b.instance;
122
107
  }
123
108
  //#region [ Actions ]
124
- addActions(e) {
125
- Array.isArray(e) && e.forEach((s) => {
126
- this.addAction(s);
109
+ addActions(t) {
110
+ Array.isArray(t) && t.forEach((e) => {
111
+ this.addAction(e);
127
112
  });
128
113
  }
129
- addAction(e) {
130
- const s = e.name;
131
- if (this._actions.has(s))
132
- throw new N(s);
133
- if (e.useEmit) {
134
- const t = (r, ...a) => this.exec(r, ...a);
135
- e.useEmit(t);
114
+ addAction(t) {
115
+ const e = t.name;
116
+ if (this._actions.has(e))
117
+ throw new M(e);
118
+ if (t.useEmit) {
119
+ const s = (i, ...a) => this.exec(i, ...a);
120
+ t.useEmit(s);
136
121
  }
137
- return this._actions.set(s, e), this.emitDIProps(e), e.watch && e.watch.forEach((t) => {
138
- const r = this._watchers.get(t) || [];
139
- r.push(s), this._watchers.set(t, r);
122
+ return j(t), this._actions.set(e, t), this.emitDIProps(t), t.$watch && t.$watch.forEach((s) => {
123
+ const i = this._watchers.get(s) || [];
124
+ i.push(e), this._watchers.set(s, i);
140
125
  }), this;
141
126
  }
142
- removeAction(e) {
143
- if (!this._actions.has(e))
144
- throw new E(e);
145
- this._actions.delete(e);
127
+ removeAction(t) {
128
+ if (!this._actions.has(t))
129
+ throw new p(t);
130
+ this._actions.delete(t);
146
131
  }
147
132
  clearActions() {
148
133
  this._actions.clear();
149
134
  }
150
135
  clearListeners() {
151
- for (const e in this._listeners)
152
- this._listeners.has(e) && this._listeners.delete(e);
153
- }
154
- async emit(e, ...s) {
155
- const t = this.getActionOrNull(e);
156
- if (t === null)
157
- throw new E(e);
158
- if (t.validateInput) {
159
- const r = await t.validateInput(...s);
160
- if (r !== !0)
161
- return this.config.errorHandlerEventName && this.emit(this.config.errorHandlerEventName, r), t.errorHandlerEventName && this.emit(t.errorHandlerEventName, r), r;
136
+ for (const t in this._listeners)
137
+ this._listeners.has(t) && this._listeners.delete(t);
138
+ }
139
+ async emit(t, ...e) {
140
+ const s = this.getActionOrNull(t);
141
+ if (s === null)
142
+ throw new p(t);
143
+ if (s.validateInput) {
144
+ const i = await s.validateInput(...e);
145
+ if (i !== !0)
146
+ return this.config.errorHandlerEventName && this.emit(this.config.errorHandlerEventName, i), s.$onError && this.emit(s.$onError, i), i;
162
147
  }
163
148
  try {
164
- const r = await t.exec(...s);
165
- return r instanceof d || d.is(r) || this.notifyListeners(e, r), r;
166
- } catch (r) {
167
- return this.catchEmitException(r, e);
149
+ const i = await s.exec(...e);
150
+ return i instanceof w || w.is(i) || this.notifyListeners(t, i), i;
151
+ } catch (i) {
152
+ return this.catchEmitException(i, t);
168
153
  }
169
154
  }
170
- catchEmitException(e, s) {
171
- if (e instanceof E)
172
- throw e;
173
- const t = this.getActionOrNull(s);
174
- 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);
175
- }
176
- notifyListeners(e, s) {
177
- const t = this._listeners.get(e);
178
- if (t && t.forEach((r) => {
179
- r(s);
180
- }), this._watchers.has(e))
181
- for (const r of this._watchers.get(e) || [])
182
- this.exec(r, s);
183
- }
184
- unsubscribe(e, s) {
185
- const t = this._listeners.get(e);
186
- if (!t)
187
- return this._subsMap.set(e, []), !1;
188
- const r = t.indexOf(s);
189
- return r > -1 && t.splice(r, 1), this._listeners.set(e, t), r > -1;
190
- }
191
- off(e, s) {
192
- return this.unsubscribe(e, s);
155
+ catchEmitException(t, e) {
156
+ if (t instanceof p)
157
+ throw t;
158
+ const s = this.getActionOrNull(e);
159
+ return s != null && s.$onError && s.$onError !== e ? (this.emit(s.$onError, t), Promise.resolve(null)) : this.config.errorHandlerEventName && this.config.errorHandlerEventName !== e ? (this.emit(this.config.errorHandlerEventName, t), Promise.resolve(null)) : Promise.reject(t);
160
+ }
161
+ notifyListeners(t, e) {
162
+ const s = this._listeners.get(t);
163
+ if (s && s.forEach((i) => {
164
+ i(e);
165
+ }), this._watchers.has(t))
166
+ for (const i of this._watchers.get(t) || [])
167
+ this.exec(i, e);
168
+ }
169
+ unsubscribe(t, e) {
170
+ const s = this._listeners.get(t);
171
+ if (!s)
172
+ return this._subsMap.set(t, []), !1;
173
+ const i = s.indexOf(e);
174
+ return i > -1 && s.splice(i, 1), this._listeners.set(t, s), i > -1;
175
+ }
176
+ off(t, e) {
177
+ return this.unsubscribe(t, e);
193
178
  }
194
179
  //#endregion
195
180
  //#region [ extends functions ]
196
- inProgress(e, s) {
197
- if (Array.isArray(e)) {
198
- e.forEach((a) => this._inProgressWatchers.set(a, s));
199
- const r = () => {
200
- e.forEach((a) => {
181
+ /**
182
+ * @deprecated
183
+ *
184
+ */
185
+ inProgress(t, e) {
186
+ if (Array.isArray(t)) {
187
+ t.forEach((a) => this._inProgressWatchers.set(a, e));
188
+ const i = () => {
189
+ t.forEach((a) => {
201
190
  this._inProgressWatchers.delete(a);
202
191
  });
203
192
  };
204
- return this._lastUnsubscribe = r, r;
193
+ return this._lastUnsubscribe = i, i;
205
194
  }
206
- this._inProgressWatchers.set(e, s);
207
- const t = () => this._inProgressWatchers.delete(e);
208
- return this._lastUnsubscribe = t, t;
195
+ this._inProgressWatchers.set(t, e);
196
+ const s = () => this._inProgressWatchers.delete(t);
197
+ return this._lastUnsubscribe = s, s;
209
198
  }
210
- setProgress(e, s) {
211
- this._inProgressWatchers.has(e) && this._inProgressWatchers.get(e)(s);
199
+ // TODO: remove in v3
200
+ setProgress(t, e) {
201
+ this._inProgressWatchers.has(t) && this._inProgressWatchers.get(t)(e);
212
202
  }
213
203
  get subsList() {
204
+ const t = (e) => {
205
+ (this._subsMap.get(e) || []).forEach((s) => s()), this._subsMap.delete(e);
206
+ };
214
207
  return {
208
+ /**
209
+ * After running this method, all subscriptions will be saved,
210
+ * and can be cleared using the
211
+ * subList.clear('key') method - with the same key passed in.
212
+ *
213
+ */
215
214
  add: (e, ...s) => {
216
- s.length || s.push(this._lastUnsubscribe);
217
- const t = this._subsMap.get(e) || [];
218
- t.push(...s), this._subsMap.set(e, t);
215
+ this._subCurrentName = e;
216
+ const i = this._subsMap.get(e) || [];
217
+ return s.length && i.push(...s), this._subsMap.set(e, i), t;
219
218
  },
220
- clear: (e) => {
221
- (this._subsMap.get(e) || []).forEach((s) => s()), this._subsMap.delete(e);
222
- }
219
+ clear: t
223
220
  };
224
221
  }
225
222
  // #endregion
@@ -227,216 +224,229 @@ const w = class b {
227
224
  clearDI() {
228
225
  this._DIContainer = {};
229
226
  }
230
- setDI(e, s) {
231
- if (this.config.errorOnReplaceDI && this._DIContainer[e])
232
- throw new M(e);
233
- return this._DIContainer[e] = s, this.freshEmitDI(), this;
227
+ setDI(t, e) {
228
+ if (this.config.errorOnReplaceDI && this._DIContainer[t])
229
+ throw new O(t);
230
+ return this._DIContainer[t] = e, this.freshEmitDI(), this;
231
+ }
232
+ getDI(t) {
233
+ return this._DIContainer[t];
234
234
  }
235
235
  freshEmitDI() {
236
- let e;
237
- Object.keys(this._actions).forEach((s) => {
238
- e = this._actions.get(s), e && this.emitDIProps(e);
236
+ let t;
237
+ Object.keys(this._actions).forEach((e) => {
238
+ t = this._actions.get(e), t && this.emitDIProps(t);
239
239
  });
240
240
  }
241
- emitDIProps(e) {
242
- e._DI_CONTAINER_ || Object.defineProperty(e, "_DI_CONTAINER_", {
241
+ emitDIProps(t) {
242
+ t._DI_CONTAINER_ || Object.defineProperty(t, "_DI_CONTAINER_", {
243
243
  get: () => this._DIContainer,
244
244
  enumerable: !1
245
245
  // Uncomment for DEBUG
246
- }), e._DI_MAP_ && Object.keys(e._DI_MAP_).forEach((s) => {
247
- var t;
248
- if (e[s])
246
+ }), t._DI_MAP_ && Object.keys(t._DI_MAP_).forEach((e) => {
247
+ var s;
248
+ if (t[e])
249
249
  return;
250
- const r = (t = e._DI_MAP_) == null ? void 0 : t[s];
251
- r && Object.defineProperty(e, s, {
250
+ const i = (s = t._DI_MAP_) == null ? void 0 : s[e];
251
+ i && Object.defineProperty(t, e, {
252
252
  get() {
253
- return this._DI_CONTAINER_[r];
253
+ return this._DI_CONTAINER_[i];
254
254
  },
255
255
  enumerable: !0
256
256
  });
257
- }), e.useDI && e.useDI(this._DIContainer);
257
+ }), t.useDI && t.useDI(this._DIContainer);
258
258
  }
259
259
  //#endregion
260
260
  //#region [ helpers ]
261
- getActionOrNull(e) {
262
- return this._actions.get(e) || null;
261
+ getActionOrNull(t) {
262
+ return this._actions.get(t) || null;
263
263
  }
264
264
  //#endregion
265
265
  };
266
- c(w, "instance");
267
- let g = w;
268
- const y = class o {
266
+ c(P, "instance");
267
+ let _ = P;
268
+ var R = Object.defineProperty, H = (r, t, e) => t in r ? R(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e, A = (r, t, e) => (H(r, typeof t != "symbol" ? t + "" : t, e), e);
269
+ function K(r) {
270
+ return function(t, e) {
271
+ const s = t;
272
+ s._DI_MAP_ || (s._DI_MAP_ = {}), s._DI_MAP_[e] = r;
273
+ };
274
+ }
275
+ function q() {
276
+ return (r, t) => {
277
+ Object.defineProperty(r, "useEmit", {
278
+ value: function(e) {
279
+ this[t] = e;
280
+ }
281
+ });
282
+ };
283
+ }
284
+ const I = class o {
269
285
  constructor() {
270
286
  }
271
- static getInstance(e = {}) {
272
- return o.resetAll(), o.removeSingleton(), o.$act = new g(e), o.$act;
287
+ static getInstance(t = {}) {
288
+ return o.resetAll(), o.removeSingleton(), o.$act = new _(t), o.$act;
289
+ }
290
+ static setInstance(t) {
291
+ o.$act = t;
292
+ }
293
+ static checkInstance(t) {
294
+ return o.$act === t;
273
295
  }
274
296
  static resetAll() {
275
297
  o.$act && (o.$act.clearActions(), o.$act.clearListeners(), o.$act.clearDI()), o._lastResult = void 0;
276
298
  }
277
299
  static removeSingleton() {
278
- g.instance = void 0, o._lastResult = void 0;
300
+ _.instance = void 0, o._lastResult = void 0;
279
301
  }
280
- static addActions(e) {
281
- o.$act.addActions(e);
302
+ static addActions(t) {
303
+ o.$act.addActions(t);
282
304
  }
283
- static exec(e, ...s) {
284
- return o.$act.exec(e, ...s).then((t) => (o._lastResult = t, t)).catch((t) => {
285
- throw o._lastResult = t, t;
305
+ static exec(t, ...e) {
306
+ return o.$act.exec(t, ...e).then((s) => (o._lastResult = s, s)).catch((s) => {
307
+ throw o._lastResult = s, s;
286
308
  });
287
309
  }
288
- static subscribe(e, s, t) {
289
- return o.$act.subscribe(e, s, t);
310
+ static subscribe(t, e, s) {
311
+ return o.$act.subscribe(t, e, s);
290
312
  }
291
- static entityCount(e) {
292
- if (e === "di")
313
+ static entityCount(t) {
314
+ if (t === "di")
293
315
  return Object.keys(o.$act._DIContainer).length;
294
- if (e === "actions")
316
+ if (t === "actions")
295
317
  return o.$act._actions.size;
296
- const s = {
318
+ const e = {
297
319
  watchers: "_watchers",
298
320
  listeners: "_listeners"
299
- }[e];
300
- let t = 0;
301
- return o.$act[s].forEach((r) => {
302
- t += r.length;
303
- }), t;
321
+ }[t];
322
+ let s = 0;
323
+ return o.$act[e].forEach((i) => {
324
+ s += i.length;
325
+ }), s;
304
326
  }
305
327
  static getLastResult() {
306
328
  return o._lastResult;
307
329
  }
308
- static makeActionStub(e) {
330
+ static makeActionStub(t) {
309
331
  return {
310
332
  name: `Act_${Math.random()}`,
311
333
  exec: () => null,
312
- ...e
334
+ ...t
313
335
  };
314
336
  }
315
337
  };
316
- c(y, "$act"), c(y, "_lastResult");
317
- let L = y;
318
- function m() {
319
- const i = g.getInstance();
320
- if (!i)
338
+ A(I, "$act"), A(I, "_lastResult");
339
+ let B = I;
340
+ function d() {
341
+ const r = _.getInstance();
342
+ if (!r)
321
343
  throw new Error(
322
344
  'Instance call before initialization. Make a "new ActMaster()" first'
323
345
  );
324
- return i;
346
+ return r;
325
347
  }
326
- m.init = (i) => new g(i);
327
- const W = (i, e, s) => {
328
- const t = m().subscribe(i, e);
329
- return s && (typeof s == "function" ? s(t) : m().subsList.add(s, t)), t;
330
- }, k = (i) => m().subsList.clear(i);
331
- m.subListClear = k;
332
- const H = (i) => {
333
- if (typeof i != "function" || !i.name)
334
- throw new Error(`Pass not valid function: "${i}"`);
348
+ d.init = (r) => new _(r);
349
+ const G = (r, t, e) => {
350
+ const s = d().subscribe(r, t);
351
+ return e && (typeof e == "function" ? e(s) : d().subsList.add(e, s)), s;
352
+ }, L = (r) => d().subsList.clear(r);
353
+ d.subListClear = L;
354
+ const U = (r) => {
355
+ if (typeof r != "function" || !r.name)
356
+ throw new Error(`Pass not valid function: "${r}"`);
335
357
  return {
336
- name: i.name,
337
- exec: i
358
+ name: r.name,
359
+ exec: r
338
360
  };
339
- }, T = H;
340
- class z {
341
- constructor() {
342
- c(this, "$emit"), c(this, "$di");
343
- }
344
- useEmit(e) {
345
- this.$emit = e;
346
- }
347
- useDI(e) {
348
- this.$di = e;
349
- }
350
- }
351
- function P(i) {
352
- return (e, s, t) => {
353
- const r = typeof e == "function" ? e : e.constructor;
354
- r.__decorators__ || (r.__decorators__ = []), typeof t != "number" && (t = void 0), r.__decorators__.push((a) => i(a, s, t));
361
+ }, J = U;
362
+ function v(r) {
363
+ return (t, e, s) => {
364
+ const i = typeof t == "function" ? t : t.constructor;
365
+ i.__decorators__ || (i.__decorators__ = []), typeof s != "number" && (s = void 0), i.__decorators__.push((a) => r(a, e, s));
355
366
  };
356
367
  }
357
- function B(i, e, s = null) {
358
- return P((t, r) => {
368
+ function Q(r, t, e = null) {
369
+ return v((s, i) => {
359
370
  const a = {
360
371
  created() {
361
372
  this.$act.subscribe(
362
- i,
363
- (l) => {
364
- const n = R(l, e, s);
365
- typeof this[r] == "function" ? this[r](n) : this[r] = n;
373
+ r,
374
+ (h) => {
375
+ const n = W(h, t, e);
376
+ typeof this[i] == "function" ? this[i](n) : this[i] = n;
366
377
  },
367
378
  this
368
379
  );
369
380
  }
370
381
  };
371
- t.mixins ? t.mixins = [...t.mixins, a] : t.mixins = [a];
382
+ s.mixins ? s.mixins = [...s.mixins, a] : s.mixins = [a];
372
383
  });
373
384
  }
374
- function R(i, e, s) {
375
- if (i === void 0)
376
- return s;
377
- if (typeof e == "function")
378
- return e(i);
379
- let t = i;
380
- if (e) {
381
- const r = (e || "").split(".");
382
- let a, l = 0;
383
- for (l = 0; l < r.length && t; l++)
384
- a = r[l], t = t[a];
385
- }
386
- return t === void 0 ? s : t;
385
+ function W(r, t, e) {
386
+ if (r === void 0)
387
+ return e;
388
+ if (typeof t == "function")
389
+ return t(r);
390
+ let s = r;
391
+ if (t) {
392
+ const i = (t || "").split(".");
393
+ let a, h = 0;
394
+ for (h = 0; h < i.length && s; h++)
395
+ a = i[h], s = s[a];
396
+ }
397
+ return s === void 0 ? e : s;
387
398
  }
388
- function F(i) {
389
- return P((e, s) => {
390
- const t = {
399
+ function X(r) {
400
+ return v((t, e) => {
401
+ const s = {
391
402
  created() {
392
- const r = this.$act.inProgress(i, (a) => {
393
- this[s] = a;
403
+ const i = this.$act.inProgress(r, (a) => {
404
+ this[e] = a;
394
405
  });
395
406
  this.$once("hook:beforeDestroy", () => {
396
- r(i);
407
+ i(r);
397
408
  });
398
409
  }
399
410
  };
400
- e.mixins ? e.mixins = [...e.mixins, t] : e.mixins = [t];
411
+ t.mixins ? t.mixins = [...t.mixins, s] : t.mixins = [s];
401
412
  });
402
413
  }
403
- const _ = class _ {
404
- static install(e, s) {
405
- var r;
406
- const t = new g({
407
- autoUnsubscribeCallback({ context: a, eventName: l, listener: n }) {
414
+ const m = class {
415
+ static install(t, e) {
416
+ var i;
417
+ const s = new _({
418
+ autoUnsubscribeCallback({ context: a, eventName: h, listener: n }) {
408
419
  a && typeof a == "function" ? a(function() {
409
- t.unsubscribe(l, n);
420
+ s.unsubscribe(h, n);
410
421
  }) : a && typeof a.$once == "function" && a.$once("hook:beforeDestroy", () => {
411
- t.unsubscribe(l, n);
422
+ s.unsubscribe(h, n);
412
423
  });
413
424
  },
414
- ...s
425
+ ...e
415
426
  });
416
- _.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);
427
+ m.instance = s, (i = t.config) != null && i.globalProperties && !t.config.globalProperties.$act ? (t.config.globalProperties.$act = s, t.provide("$act", s)) : Object.prototype.hasOwnProperty.call(t, "$act") || (t.act = s, t.prototype.$act = s);
417
428
  }
418
- install(e, s) {
419
- _.install(e, s);
429
+ install(t, e) {
430
+ m.install(t, e);
420
431
  }
421
432
  };
422
- I(_, "instance", null);
423
- let A = _;
433
+ let E = m;
434
+ $(E, "instance", null);
424
435
  export {
425
- F as ActInProgress,
426
- g as ActMaster,
427
- B as ActSubscribe,
428
- L as ActTest,
429
- N as ActinonAlreadyExistingError,
430
- z as BaseActMasterAction,
431
- d as CancelledAct,
432
- U as Emit,
433
- C as InvalidDITypeError,
434
- M as KeyAlreadyExistsInDIError,
435
- E as NotFoundActionError,
436
- S as UseDI,
437
- A as VueActMaster,
438
- m as act,
439
- W as actSubscribe,
440
- T as fn2act,
441
- H as functionToAction
436
+ X as ActInProgress,
437
+ _ as ActMaster,
438
+ Q as ActSubscribe,
439
+ B as ActTest,
440
+ M as ActinonAlreadyExistingError,
441
+ w as CancelledAct,
442
+ q as Emit,
443
+ S as InvalidDITypeError,
444
+ O as KeyAlreadyExistsInDIError,
445
+ p as NotFoundActionError,
446
+ K as UseDI,
447
+ E as VueActMaster,
448
+ d as act,
449
+ G as actSubscribe,
450
+ J as fn2act,
451
+ U as functionToAction
442
452
  };
@@ -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 B=Object.defineProperty;var F=(c,h,d)=>h in c?B(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,o=(i,e,s)=>(d(i,typeof e!="symbol"?e+"":e,s),s);class g{constructor(e,s){if(o(this,"reason",""),o(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 D extends Error{constructor(e){super(`Action "${e}" already existing`),this.eventName=e}}class v 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.2.0";function j(i){return function(e,s){const t=e;t._DI_MAP_||(t._DI_MAP_={}),t._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(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(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}),o(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),_}),o(this,"once",(n,b)=>{const f=this.subscribe(n,(..._)=>{f(),b(..._)});return f}),o(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 D(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 v(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}};o(M,"instance");let m=M;const p=class l{constructor(){}static getInstance(e={}){return l.resetAll(),l.removeSingleton(),l.$act=new m(e),l.$act}static resetAll(){l.$act&&(l.$act.clearActions(),l.$act.clearListeners(),l.$act.clearDI()),l._lastResult=void 0}static removeSingleton(){m.instance=void 0,l._lastResult=void 0}static addActions(e){l.$act.addActions(e)}static exec(e,...s){return l.$act.exec(e,...s).then(t=>(l._lastResult=t,t)).catch(t=>{throw l._lastResult=t,t})}static subscribe(e,s,t){return l.$act.subscribe(e,s,t)}static entityCount(e){if(e==="di")return Object.keys(l.$act._DIContainer).length;if(e==="actions")return l.$act._actions.size;const s={watchers:"_watchers",listeners:"_listeners"}[e];let t=0;return l.$act[s].forEach(r=>{t+=r.length}),t}static getLastResult(){return l._lastResult}static makeActionStub(e){return{name:`Act_${Math.random()}`,exec:()=>null,...e}}};o(p,"$act"),o(p,"_lastResult");let H=p;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;class L{constructor(){o(this,"$emit"),o(this,"$di")}useEmit(e){this.$emit=e}useDI(e){this.$di=e}}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 T(i,e,s=null){return C((t,r)=>{const a={created(){this.$act.subscribe(i,u=>{const n=W(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 W(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 z(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 A=class A{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});A.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){A.install(e,s)}};O(A,"instance",null);let w=A;c.ActInProgress=z,c.ActMaster=m,c.ActSubscribe=T,c.ActTest=H,c.ActinonAlreadyExistingError=D,c.BaseActMasterAction=L,c.CancelledAct=g,c.Emit=k,c.InvalidDITypeError=$,c.KeyAlreadyExistsInDIError=v,c.NotFoundActionError=I,c.UseDI=j,c.VueActMaster=w,c.act=y,c.actSubscribe=R,c.fn2act=x,c.functionToAction=N,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
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 G=Object.defineProperty;var J=(c,h,_)=>h in c?G(c,h,{enumerable:!0,configurable:!0,writable:!0,value:_}):c[h]=_;var j=(c,h,_)=>(J(c,typeof h!="symbol"?h+"":h,_),_);var h=Object.defineProperty,_=(r,t,s)=>t in r?h(r,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[t]=s,l=(r,t,s)=>(_(r,typeof t!="symbol"?t+"":t,s),s);let w=class P{constructor(t,s){if(l(this,"reason",""),l(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 P._name}static is(t){return!t||typeof t!="object"?!1:t._name===P._name}valueOf(){return null}toString(){return this.reason}};class E extends Error{constructor(t){super(`Can't find "${t}" action`),this.eventName=t}}class v extends Error{constructor(t){super(`Action "${t}" already existing`),this.eventName=t}}let D=class extends Error{constructor(t){super(`"${t}" already exists in DI`),this.key=t}},C=class extends Error{constructor(){super(`"di" can't be array`)}};const k="2.3.6",R=r=>{r.watch&&!r.$watch&&(r.$watch=r.watch),r.isSingleExec&&typeof r.$isSingleton!="boolean"&&(r.$isSingleton=r.isSingleExec),r.validateInput&&!r.$validate&&(r.$validate=r.validateInput),r.errorHandlerEventName&&!r.$onError&&(r.$onError=r.errorHandlerEventName)},N=class y{constructor(t={}){if(l(this,"version",k),l(this,"_actions",new Map),l(this,"_watchers",new Map),l(this,"_listeners",new Map),l(this,"_inProgressWatchers",new Map),l(this,"_subCurrentName",""),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,...d)=>{if(this.setProgress(n,!0),this._singlePromisesStore.has(n)){const p=this._singlePromisesStore.get(n);if(p)return p}const u=this.emit(n,...d).catch(p=>this.catchEmitException(p,n)).finally(()=>{this._singlePromisesStore.has(n)&&this._singlePromisesStore.delete(n),this.setProgress(n,!1)}),b=this.getActionOrNull(n);return b&&b.$isSingleton&&this._singlePromisesStore.set(n,u),u}),l(this,"subscribe",(n,d,u)=>{this._listeners.set(n,[...this._listeners.get(n)||[],d]);const b=()=>this.unsubscribe(n,d);return this._lastUnsubscribe=b,this.config.autoUnsubscribeCallback&&this.config.autoUnsubscribeCallback({context:u,listener:d,eventName:n}),u?typeof u=="function"?u(b):this.subsList.add(u,b):this._subCurrentName&&this.subsList.add(this._subCurrentName,b),b}),l(this,"once",(n,d)=>{const u=this.subscribe(n,(...b)=>{u(),d(...b)});return u}),l(this,"on",(n,d,u)=>this.subscribe(n,d,u)),y.instance)return y.instance;const{actions:s,di:e,errorOnReplaceDI:i,autoUnsubscribeCallback:a,errorHandlerEventName:f}=t;if(s&&this.addActions(s),typeof a=="function"&&(this.config.autoUnsubscribeCallback=a),typeof e=="object"&&e){if(Array.isArray(e))throw new C;for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&this.setDI(n,e[n])}typeof i=="boolean"&&(this.config.errorOnReplaceDI=i),typeof f=="string"&&(this.config.errorHandlerEventName=f),y.instance=this}static getInstance(){if(!y.instance)throw new Error("ActMaster not initialized");return y.instance}addActions(t){Array.isArray(t)&&t.forEach(s=>{this.addAction(s)})}addAction(t){const s=t.name;if(this._actions.has(s))throw new v(s);if(t.useEmit){const e=(i,...a)=>this.exec(i,...a);t.useEmit(e)}return R(t),this._actions.set(s,t),this.emitDIProps(t),t.$watch&&t.$watch.forEach(e=>{const i=this._watchers.get(e)||[];i.push(s),this._watchers.set(e,i)}),this}removeAction(t){if(!this._actions.has(t))throw new E(t);this._actions.delete(t)}clearActions(){this._actions.clear()}clearListeners(){for(const t in this._listeners)this._listeners.has(t)&&this._listeners.delete(t)}async emit(t,...s){const e=this.getActionOrNull(t);if(e===null)throw new E(t);if(e.validateInput){const i=await e.validateInput(...s);if(i!==!0)return this.config.errorHandlerEventName&&this.emit(this.config.errorHandlerEventName,i),e.$onError&&this.emit(e.$onError,i),i}try{const i=await e.exec(...s);return i instanceof w||w.is(i)||this.notifyListeners(t,i),i}catch(i){return this.catchEmitException(i,t)}}catchEmitException(t,s){if(t instanceof E)throw t;const e=this.getActionOrNull(s);return e!=null&&e.$onError&&e.$onError!==s?(this.emit(e.$onError,t),Promise.resolve(null)):this.config.errorHandlerEventName&&this.config.errorHandlerEventName!==s?(this.emit(this.config.errorHandlerEventName,t),Promise.resolve(null)):Promise.reject(t)}notifyListeners(t,s){const e=this._listeners.get(t);if(e&&e.forEach(i=>{i(s)}),this._watchers.has(t))for(const i of this._watchers.get(t)||[])this.exec(i,s)}unsubscribe(t,s){const e=this._listeners.get(t);if(!e)return this._subsMap.set(t,[]),!1;const i=e.indexOf(s);return i>-1&&e.splice(i,1),this._listeners.set(t,e),i>-1}off(t,s){return this.unsubscribe(t,s)}inProgress(t,s){if(Array.isArray(t)){t.forEach(a=>this._inProgressWatchers.set(a,s));const i=()=>{t.forEach(a=>{this._inProgressWatchers.delete(a)})};return this._lastUnsubscribe=i,i}this._inProgressWatchers.set(t,s);const e=()=>this._inProgressWatchers.delete(t);return this._lastUnsubscribe=e,e}setProgress(t,s){this._inProgressWatchers.has(t)&&this._inProgressWatchers.get(t)(s)}get subsList(){const t=s=>{(this._subsMap.get(s)||[]).forEach(e=>e()),this._subsMap.delete(s)};return{add:(s,...e)=>{this._subCurrentName=s;const i=this._subsMap.get(s)||[];return e.length&&i.push(...e),this._subsMap.set(s,i),t},clear:t}}clearDI(){this._DIContainer={}}setDI(t,s){if(this.config.errorOnReplaceDI&&this._DIContainer[t])throw new D(t);return this._DIContainer[t]=s,this.freshEmitDI(),this}getDI(t){return this._DIContainer[t]}freshEmitDI(){let t;Object.keys(this._actions).forEach(s=>{t=this._actions.get(s),t&&this.emitDIProps(t)})}emitDIProps(t){t._DI_CONTAINER_||Object.defineProperty(t,"_DI_CONTAINER_",{get:()=>this._DIContainer,enumerable:!1}),t._DI_MAP_&&Object.keys(t._DI_MAP_).forEach(s=>{var e;if(t[s])return;const i=(e=t._DI_MAP_)==null?void 0:e[s];i&&Object.defineProperty(t,s,{get(){return this._DI_CONTAINER_[i]},enumerable:!0})}),t.useDI&&t.useDI(this._DIContainer)}getActionOrNull(t){return this._actions.get(t)||null}};l(N,"instance");let g=N;var H=Object.defineProperty,x=(r,t,s)=>t in r?H(r,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[t]=s,M=(r,t,s)=>(x(r,typeof t!="symbol"?t+"":t,s),s);function L(r){return function(t,s){const e=t;e._DI_MAP_||(e._DI_MAP_={}),e._DI_MAP_[s]=r}}function U(){return(r,t)=>{Object.defineProperty(r,"useEmit",{value:function(s){this[t]=s}})}}const A=class o{constructor(){}static getInstance(t={}){return o.resetAll(),o.removeSingleton(),o.$act=new g(t),o.$act}static setInstance(t){o.$act=t}static checkInstance(t){return o.$act===t}static resetAll(){o.$act&&(o.$act.clearActions(),o.$act.clearListeners(),o.$act.clearDI()),o._lastResult=void 0}static removeSingleton(){g.instance=void 0,o._lastResult=void 0}static addActions(t){o.$act.addActions(t)}static exec(t,...s){return o.$act.exec(t,...s).then(e=>(o._lastResult=e,e)).catch(e=>{throw o._lastResult=e,e})}static subscribe(t,s,e){return o.$act.subscribe(t,s,e)}static entityCount(t){if(t==="di")return Object.keys(o.$act._DIContainer).length;if(t==="actions")return o.$act._actions.size;const s={watchers:"_watchers",listeners:"_listeners"}[t];let e=0;return o.$act[s].forEach(i=>{e+=i.length}),e}static getLastResult(){return o._lastResult}static makeActionStub(t){return{name:`Act_${Math.random()}`,exec:()=>null,...t}}};M(A,"$act"),M(A,"_lastResult");let T=A;function m(){const r=g.getInstance();if(!r)throw new Error('Instance call before initialization. Make a "new ActMaster()" first');return r}m.init=r=>new g(r);const W=(r,t,s)=>{const e=m().subscribe(r,t);return s&&(typeof s=="function"?s(e):m().subsList.add(s,e)),e},z=r=>m().subsList.clear(r);m.subListClear=z;const O=r=>{if(typeof r!="function"||!r.name)throw new Error(`Pass not valid function: "${r}"`);return{name:r.name,exec:r}},F=O;function S(r){return(t,s,e)=>{const i=typeof t=="function"?t:t.constructor;i.__decorators__||(i.__decorators__=[]),typeof e!="number"&&(e=void 0),i.__decorators__.push(a=>r(a,s,e))}}function K(r,t,s=null){return S((e,i)=>{const a={created(){this.$act.subscribe(r,f=>{const n=q(f,t,s);typeof this[i]=="function"?this[i](n):this[i]=n},this)}};e.mixins?e.mixins=[...e.mixins,a]:e.mixins=[a]})}function q(r,t,s){if(r===void 0)return s;if(typeof t=="function")return t(r);let e=r;if(t){const i=(t||"").split(".");let a,f=0;for(f=0;f<i.length&&e;f++)a=i[f],e=e[a]}return e===void 0?s:e}function B(r){return S((t,s)=>{const e={created(){const i=this.$act.inProgress(r,a=>{this[s]=a});this.$once("hook:beforeDestroy",()=>{i(r)})}};t.mixins?t.mixins=[...t.mixins,e]:t.mixins=[e]})}const $=class{static install(t,s){var i;const e=new g({autoUnsubscribeCallback({context:a,eventName:f,listener:n}){a&&typeof a=="function"?a(function(){e.unsubscribe(f,n)}):a&&typeof a.$once=="function"&&a.$once("hook:beforeDestroy",()=>{e.unsubscribe(f,n)})},...s});$.instance=e,(i=t.config)!=null&&i.globalProperties&&!t.config.globalProperties.$act?(t.config.globalProperties.$act=e,t.provide("$act",e)):Object.prototype.hasOwnProperty.call(t,"$act")||(t.act=e,t.prototype.$act=e)}install(t,s){$.install(t,s)}};let I=$;j(I,"instance",null),c.ActInProgress=B,c.ActMaster=g,c.ActSubscribe=K,c.ActTest=T,c.ActinonAlreadyExistingError=v,c.CancelledAct=w,c.Emit=U,c.InvalidDITypeError=C,c.KeyAlreadyExistsInDIError=D,c.NotFoundActionError=E,c.UseDI=L,c.VueActMaster=I,c.act=m,c.actSubscribe=W,c.fn2act=F,c.functionToAction=O,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.2.0",
3
+ "version": "2.3.6",
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.2.0"
55
+ "act-master": "^2.3.6"
56
56
  },
57
57
  "peerDependencies": {
58
- "act-master": "^2.2.0"
58
+ "act-master": "^2.3.6"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@babel/types": "^7.22.5",