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