vue-fn 0.1.0-beta.0 → 0.1.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/domain/index.mjs CHANGED
@@ -1,199 +1,209 @@
1
- import { ref as b, computed as m, shallowRef as P, shallowReactive as S, watch as E, readonly as w, triggerRef as C, effectScope as F, onScopeDispose as M, shallowReadonly as y } from "vue";
1
+ import { ref as E, computed as m, shallowRef as P, shallowReactive as S, watch as b, readonly as I, triggerRef as C, effectScope as M, onScopeDispose as F, shallowReadonly as y } from "vue";
2
2
  import { n as T } from "../index.browser-CWCjzKuA.js";
3
- function I(r, o = !0, a = !1) {
4
- const n = b();
5
- let e;
6
- const t = b(!1);
7
- let i = () => {
3
+ function g(s, i = !0, u = !1) {
4
+ const c = E();
5
+ let t;
6
+ const r = E(!1);
7
+ let e = () => {
8
8
  };
9
- const u = new Proxy(r, {
10
- apply: function(c, d, s) {
11
- let l;
9
+ const n = new Proxy(s, {
10
+ apply: function(l, f, a) {
11
+ let d;
12
12
  try {
13
- l = c(...s);
13
+ d = l(...a);
14
14
  } catch (p) {
15
- l = p;
15
+ d = p;
16
16
  }
17
- if (l instanceof Error) {
18
- if (n.value = l, e = l, o)
19
- throw i(), l;
17
+ if (d instanceof Error) {
18
+ if (c.value = d, t = d, i)
19
+ throw e(), d;
20
20
  } else
21
- t.value = !0, n.value = void 0, e = !0, i();
21
+ r.value = !0, c.value = void 0, t = !0, e();
22
22
  }
23
- }), f = () => {
23
+ }), o = () => {
24
24
  }, v = new Proxy(
25
- (c) => {
26
- n.value = c;
25
+ (l) => {
26
+ c.value = l;
27
27
  },
28
28
  {
29
- apply: function(c, d, s) {
30
- c(...s), f(...s);
29
+ apply: function(l, f, a) {
30
+ l(...a), o(...a);
31
31
  }
32
32
  }
33
33
  );
34
34
  return {
35
- promise: new Promise((c, d) => {
36
- if (o && e instanceof Error) {
37
- d(e);
35
+ promise: new Promise((l, f) => {
36
+ if (i && t instanceof Error) {
37
+ f(t);
38
38
  return;
39
- } else if (e === !0) {
40
- c();
39
+ } else if (t === !0) {
40
+ l();
41
41
  return;
42
42
  }
43
- let s;
44
- a && (s = setTimeout(() => {
45
- const l = new Error("timeout!");
46
- n.value = l, o && d(l);
47
- }, a)), i = () => {
48
- s && (clearTimeout(s), s = void 0), c();
43
+ let a;
44
+ u && (a = setTimeout(() => {
45
+ const d = new Error("timeout!");
46
+ c.value = d, i && f(d);
47
+ }, u)), e = () => {
48
+ a && (clearTimeout(a), a = void 0), l();
49
49
  };
50
50
  }),
51
- callback: u,
51
+ callback: n,
52
52
  onError: v,
53
- resolved: m(() => t.value),
54
- error: m(() => n.value)
53
+ resolved: m(() => r.value),
54
+ error: m(() => c.value)
55
55
  };
56
56
  }
57
- function g() {
57
+ function w() {
58
58
  return T();
59
59
  }
60
- const q = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
60
+ const D = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
61
61
  __proto__: null,
62
- createPromiseCallback: I,
63
- genId: g
62
+ createPromiseCallback: g,
63
+ genId: w
64
64
  }, Symbol.toStringTag, { value: "Module" }));
65
- function D(r, o, a = !1, n = !1) {
66
- let e = P("0");
67
- const t = {}, i = S([]);
68
- function u(c, d, s, l, p) {
69
- const _ = k(e.value), z = E([l, p], ([H, R]) => {
70
- (!t[_] || H || a && R) && (z(), delete t[_]);
65
+ function G(s, i, u = !1, c = !1) {
66
+ let t = P("0");
67
+ const r = {}, e = S([]);
68
+ function n(l, f, a, d, p) {
69
+ const _ = k(t.value), z = b([d, p], ([j, R]) => {
70
+ (!r[_] || j || u && R) && (z(), delete r[_]);
71
71
  });
72
- t[_] = {
73
- data: w(c),
74
- reply: d,
75
- onError: s,
76
- resolved: l,
72
+ r[_] = {
73
+ data: I(l),
74
+ reply: f,
75
+ onError: a,
76
+ resolved: d,
77
77
  error: p
78
- }, e.value = _;
78
+ }, t.value = _;
79
79
  }
80
- const f = (c) => {
81
- const d = E(e, (s) => {
82
- if (!(!t[s] || t[s].resolved.value || a && t[s].error.value))
80
+ const o = (l) => {
81
+ const f = b(t, (a) => {
82
+ if (!(!r[a] || r[a].resolved.value || u && r[a].error.value))
83
83
  try {
84
- c({
85
- data: t[s].data,
86
- version: s,
87
- reply: t[s].reply
84
+ l({
85
+ data: r[a].data,
86
+ version: a,
87
+ reply: r[a].reply
88
88
  });
89
- } catch (l) {
90
- t[s].error.value || t[s].onError(l);
89
+ } catch (d) {
90
+ r[a].error.value || r[a].onError(d);
91
91
  }
92
92
  });
93
- return i.push(d), t[e.value] && C(e), d;
94
- }, v = async (c) => {
95
- const { promise: d, callback: s, resolved: l, error: p, onError: _ } = I(o, a, n);
96
- u(c, s, _, l, p), await d;
93
+ return e.push(f), r[t.value] && C(t), f;
94
+ }, v = async (l) => {
95
+ const { promise: f, callback: a, resolved: d, error: p, onError: _ } = g(i, u, c);
96
+ n(l, a, _, d, p), await f;
97
97
  }, h = {
98
- latestVersion: m(() => e),
99
- watchPublishRequest: f
98
+ latestVersion: m(() => t),
99
+ watchPublishRequest: o
100
100
  };
101
101
  return {
102
- watchHandles: i,
102
+ watchHandles: e,
103
103
  publishRequest: v,
104
104
  api: h
105
105
  };
106
106
  }
107
- function x(r) {
108
- let o = P("0");
109
- const a = {}, n = S([]);
110
- function e(u) {
111
- const f = k(o.value);
112
- a[f] = { data: w(u) }, o.value = f;
107
+ function x(s) {
108
+ let i = P("0");
109
+ const u = {}, c = S([]);
110
+ function t(n) {
111
+ const o = k(i.value);
112
+ u[o] = { data: I(n) }, i.value = o;
113
113
  }
114
- const t = (u) => E(o, (f) => {
115
- u({
116
- data: a[f].data,
117
- version: f
114
+ const r = (n) => b(i, (o) => {
115
+ n({
116
+ data: u[o].data,
117
+ version: o
118
118
  });
119
- }), i = {
120
- latestVersion: m(() => o),
121
- watchPublish: t
119
+ }), e = {
120
+ latestVersion: m(() => i),
121
+ watchPublish: r
122
122
  };
123
123
  return {
124
- watchHandles: n,
125
- publish: async (u) => {
126
- e(u);
124
+ watchHandles: c,
125
+ publish: async (n) => {
126
+ t(n);
127
127
  },
128
- api: i
128
+ api: e
129
129
  };
130
130
  }
131
- function k(r) {
132
- if (+r < Number.MAX_SAFE_INTEGER)
133
- return (parseInt(r) + 1).toString();
134
- let o = r.split("").reverse().join(""), a = "1";
135
- const n = Math.max(o.length, a.length);
136
- let e = 0, t = [];
137
- for (let i = 0; i < n; i++) {
138
- const u = i < o.length ? parseInt(o[i], 10) : 0, f = i < a.length ? parseInt(a[i], 10) : 0, v = u + f + e;
139
- t.push(v % 10), e = Math.floor(v / 10);
131
+ function k(s) {
132
+ if (+s < Number.MAX_SAFE_INTEGER)
133
+ return (parseInt(s) + 1).toString();
134
+ let i = s.split("").reverse().join(""), u = "1";
135
+ const c = Math.max(i.length, u.length);
136
+ let t = 0, r = [];
137
+ for (let e = 0; e < c; e++) {
138
+ const n = e < i.length ? parseInt(i[e], 10) : 0, o = e < u.length ? parseInt(u[e], 10) : 0, v = n + o + t;
139
+ r.push(v % 10), t = Math.floor(v / 10);
140
140
  }
141
- return e > 0 && t.push(e), t.reverse().join("");
141
+ return t > 0 && r.push(t), r.reverse().join("");
142
142
  }
143
- function A() {
144
- const r = {}, o = {}, a = /* @__PURE__ */ new WeakMap(), n = {};
143
+ function A(s) {
144
+ const i = {}, u = {}, c = /* @__PURE__ */ new WeakMap(), t = {}, r = [];
145
145
  return Object.freeze({
146
146
  registerAgg(e) {
147
147
  if (e.isInitialized.value)
148
148
  throw new Error("Agg must register before initialized");
149
- if (n[e.__id])
149
+ if (t[e.__id])
150
150
  throw new Error("Agg already registered");
151
151
  e.type === "MultiInstance" && e.api.events.destroyed.watchPublish(() => {
152
- delete n[e.__id];
153
- }), n[e.__id] = e;
154
- const t = [];
155
- for (const i of Object.values(r))
156
- i.mount({ api: e.api, __aggId: e.__id, isInitialized: e.isInitialized });
157
- for (const i of Object.values(o))
158
- i.mount({ api: e.api, __aggId: e.__id }), t.push(i.__id);
159
- a.set(e, t);
152
+ delete t[e.__id];
153
+ }), t[e.__id] = e;
154
+ const n = [];
155
+ for (const o of Object.values(i))
156
+ o.mount({ api: e.api, __aggId: e.__id, isInitialized: e.isInitialized });
157
+ for (const o of Object.values(u))
158
+ o.mount({ api: e.api, __aggId: e.__id }), n.push(o.__id);
159
+ if (c.set(e, n), B(e)) {
160
+ const o = e.api.events.destroyed.watchPublish(() => {
161
+ delete t[e.__id], s?.(e);
162
+ for (const v of r)
163
+ v(e);
164
+ o?.();
165
+ });
166
+ }
167
+ },
168
+ onDestroy(e) {
169
+ r.push(e);
160
170
  },
161
171
  createSetupPlugin(e) {
162
- let t;
163
- return e instanceof Function ? t = e() : t = e, Object.freeze({
164
- __id: g(),
172
+ let n;
173
+ return e instanceof Function ? n = e() : n = e, Object.freeze({
174
+ __id: w(),
165
175
  type: "Setup",
166
- mount(i) {
167
- if (i.isInitialized.value)
176
+ mount(o) {
177
+ if (o.isInitialized.value)
168
178
  throw new Error("Can not setup after initialized");
169
- t.mount({ api: i.api, __aggId: i.__aggId });
179
+ n.mount({ api: o.api, __aggId: o.__aggId });
170
180
  }
171
181
  });
172
182
  },
173
183
  createHotSwapPlugin(e) {
174
- let t;
175
- return e instanceof Function ? t = e() : t = e, Object.freeze({
176
- __id: g(),
184
+ let n;
185
+ return e instanceof Function ? n = e() : n = e, Object.freeze({
186
+ __id: w(),
177
187
  type: "HotSwap",
178
- mount: t.mount,
179
- unmount: t.unmount
188
+ mount: n.mount,
189
+ unmount: n.unmount
180
190
  });
181
191
  },
182
192
  registerPlugin(e) {
183
193
  if (e.type === "Setup") {
184
- if (r[e.__id])
194
+ if (i[e.__id])
185
195
  throw new Error("Plugin already registered");
186
- r[e.__id] = e;
187
- for (const t in n)
196
+ i[e.__id] = e;
197
+ for (const n in t)
188
198
  e.mount({
189
- api: n[t].api,
190
- __aggId: n[t].__id,
191
- isInitialized: n[t].isInitialized
199
+ api: t[n].api,
200
+ __aggId: t[n].__id,
201
+ isInitialized: t[n].isInitialized
192
202
  });
193
203
  } else if (e.type === "HotSwap") {
194
- o[e.__id] = e;
195
- for (const t in n)
196
- a.has(n[t]) && !a.get(n[t]).includes(e.__id) && (e.mount({ api: n[t].api, __aggId: n[t].__id }), a.get(n[t]).push(e.__id));
204
+ u[e.__id] = e;
205
+ for (const n in t)
206
+ c.has(t[n]) && !c.get(t[n]).includes(e.__id) && (e.mount({ api: t[n].api, __aggId: t[n].__id }), c.get(t[n]).push(e.__id));
197
207
  } else
198
208
  isNever(e);
199
209
  },
@@ -201,165 +211,170 @@ function A() {
201
211
  if (e.type === "Setup")
202
212
  throw new Error("Can not unregister setup plugin");
203
213
  if (e.type === "HotSwap") {
204
- for (const t in n)
205
- a.has(n[t]) && a.get(n[t]).includes(e.__id) && e.unmount({ api: n[t].api, __aggId: n[t].__id });
206
- delete o[e.__id];
214
+ for (const n in t)
215
+ c.has(t[n]) && c.get(t[n]).includes(e.__id) && e.unmount({ api: t[n].api, __aggId: t[n].__id });
216
+ delete u[e.__id];
207
217
  } else
208
218
  isNever(e);
209
219
  }
210
220
  });
211
221
  }
212
- function G(r) {
213
- return A();
222
+ function U(s, i) {
223
+ return A(i);
214
224
  }
215
- function U(r) {
225
+ function W(s) {
216
226
  return A();
217
227
  }
218
- function B(r) {
219
- return j(r);
228
+ function B(s) {
229
+ return s.type === "MultiInstance";
230
+ }
231
+ function N(s) {
232
+ return H(s);
220
233
  }
221
- function N(r) {
222
- const o = j(r);
234
+ function O(s) {
235
+ const i = H(s);
223
236
  return y({
224
- states: o.states,
225
- commands: o.commands,
226
- events: o.events
237
+ states: i.states,
238
+ commands: i.commands,
239
+ events: i.events
227
240
  });
228
241
  }
229
- function j(r) {
230
- const o = r.states;
231
- for (const i of Object.keys(r.states))
232
- o[i] = w(o[i]);
233
- const a = y(r.states), n = w(r.commands), e = {}, t = r.events;
234
- for (const i in r.events)
235
- e[i] = t[i].api;
242
+ function H(s) {
243
+ const i = s.states;
244
+ for (const e of Object.keys(s.states))
245
+ i[e] = I(i[e]);
246
+ const u = y(s.states), c = I(s.commands), t = {}, r = s.events;
247
+ for (const e in s.events)
248
+ t[e] = r[e].api;
236
249
  return y({
237
- states: a,
238
- commands: n,
239
- events: y(e),
240
- destroy: r.destroy
250
+ states: u,
251
+ commands: c,
252
+ events: y(t),
253
+ destroy: s.destroy
241
254
  });
242
255
  }
243
- function W(r, o) {
256
+ function X(s, i) {
244
257
  const {
245
- callback: a,
246
- onError: n,
247
- promise: e,
248
- resolved: t
249
- } = I(() => {
258
+ callback: u,
259
+ onError: c,
260
+ promise: t,
261
+ resolved: r
262
+ } = g(() => {
250
263
  }, !1, 5e3);
251
- function i(p) {
252
- if (t.value === !0)
264
+ function e(p) {
265
+ if (r.value === !0)
253
266
  throw new Error("Agg already initialized");
254
- u.push(p());
267
+ n.push(p());
255
268
  }
256
- const u = [];
269
+ const n = [];
257
270
  setTimeout(
258
- () => Promise.all(u).then(() => {
259
- a();
271
+ () => Promise.all(n).then(() => {
272
+ u();
260
273
  }).catch((p) => {
261
- n(p);
262
- })
274
+ c(p);
275
+ }),
276
+ 0
263
277
  );
264
- const f = F(), v = f.run(
265
- () => o({
278
+ const o = M(), v = o.run(
279
+ () => i({
266
280
  getCurrentScope() {
267
- return f;
281
+ return o;
268
282
  },
269
- onScopeDispose: M,
283
+ onScopeDispose: F,
270
284
  onCreated(p) {
271
285
  Promise.resolve().then(p);
272
286
  },
273
- onBeforeInitialize: i,
274
- isInitialized: m(() => t.value),
275
- untilInitialized: e
287
+ onBeforeInitialize: e,
288
+ isInitialized: m(() => r.value),
289
+ untilInitialized: t
276
290
  })
277
- ), h = v.states || {}, c = v.commands || {}, d = v.events || {};
278
- let s;
279
- d.destroyed ? s = d.destroyed : (s = x(), d.destroyed = s);
280
- let l = v.destroy;
281
- return l || (l = () => {
282
- s?.publish({});
283
- for (const p in d) {
284
- const _ = d[p];
291
+ ), h = v.states || {}, l = v.commands || {}, f = v.events || {};
292
+ let a;
293
+ f.destroyed ? a = f.destroyed : (a = x(), f.destroyed = a);
294
+ let d = v.destroy;
295
+ return d || (d = () => {
296
+ a?.publish({});
297
+ for (const p in f) {
298
+ const _ = f[p];
285
299
  for (const z of _.watchHandles)
286
300
  z.stop();
287
301
  }
288
- f.stop();
302
+ o.stop();
289
303
  }), y({
290
- __id: g(),
304
+ __id: w(),
291
305
  type: "MultiInstance",
292
- id: r,
293
- api: B({
306
+ id: s,
307
+ api: N({
294
308
  states: h,
295
- commands: c,
296
- events: d,
297
- destroy: l
309
+ commands: l,
310
+ events: f,
311
+ destroy: d
298
312
  }),
299
- isInitialized: t,
313
+ isInitialized: r,
300
314
  async untilInitialized() {
301
- return await e.catch((p) => {
315
+ return await t.catch((p) => {
302
316
  throw new Error(`Failed to initialize Agg: ${p.message}
303
317
  Stack : ${p.stack || "unkown"}`);
304
318
  });
305
319
  }
306
320
  });
307
321
  }
308
- function X(r) {
322
+ function J(s) {
309
323
  const {
310
- callback: o,
311
- onError: a,
312
- promise: n,
313
- resolved: e
314
- } = I(() => {
324
+ callback: i,
325
+ onError: u,
326
+ promise: c,
327
+ resolved: t
328
+ } = g(() => {
315
329
  }, !1, 5e3);
316
- function t(c) {
317
- if (e.value === !0)
330
+ function r(l) {
331
+ if (t.value === !0)
318
332
  throw new Error("Agg already initialized");
319
- i.push(c());
333
+ e.push(l());
320
334
  }
321
- const i = [], u = r({
322
- onCreated(c) {
323
- Promise.resolve().then(c);
335
+ const e = [], n = s({
336
+ onCreated(l) {
337
+ Promise.resolve().then(l);
324
338
  },
325
- onBeforeInitialize: t,
326
- isInitialized: m(() => e.value),
327
- untilInitialized: n
339
+ onBeforeInitialize: r,
340
+ isInitialized: m(() => t.value),
341
+ untilInitialized: c
328
342
  });
329
343
  setTimeout(
330
- () => Promise.all(i).then(() => {
331
- o();
332
- }).catch((c) => {
333
- a(c);
334
- })
344
+ () => Promise.all(e).then(() => {
345
+ i();
346
+ }).catch((l) => {
347
+ u(l);
348
+ }),
349
+ 0
335
350
  );
336
- const f = u.states || {}, v = u.commands || {}, h = u.events || {};
351
+ const o = n.states || {}, v = n.commands || {}, h = n.events || {};
337
352
  return {
338
- __id: g(),
353
+ __id: w(),
339
354
  type: "Singleton",
340
- api: N({
341
- states: f,
355
+ api: O({
356
+ states: o,
342
357
  commands: v,
343
358
  events: h,
344
359
  destroy: () => {
345
360
  }
346
361
  }),
347
- isInitialized: e,
362
+ isInitialized: t,
348
363
  async untilInitialized() {
349
- return await n.catch((c) => {
350
- throw new Error(`Failed to initialize Agg: ${c.message}
351
- Stack : ${c.stack || "unkown"}`);
364
+ return await c.catch((l) => {
365
+ throw new Error(`Failed to initialize Agg: ${l.message}
366
+ Stack : ${l.stack || "unkown"}`);
352
367
  });
353
368
  }
354
369
  };
355
370
  }
356
371
  export {
357
- q as Utils,
372
+ D as Utils,
358
373
  x as createBroadcastEvent,
359
- W as createMultiInstanceAgg,
360
- U as createPluginHelperByAgg,
361
- G as createPluginHelperByAggCreator,
362
- D as createRequestEvent,
363
- X as createSingletonAgg
374
+ X as createMultiInstanceAgg,
375
+ W as createPluginHelperByAgg,
376
+ U as createPluginHelperByAggCreator,
377
+ G as createRequestEvent,
378
+ J as createSingletonAgg
364
379
  };
365
380
  //# sourceMappingURL=index.mjs.map