vue-fn 0.1.0-rc.3 → 0.1.0-rc.4

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