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