vue-fn 0.2.0-rc → 0.4.0-rc

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.
Files changed (38) hide show
  1. package/domain/agg.d.ts +1 -1
  2. package/domain/bind.d.ts +4 -1
  3. package/domain/event.d.ts +7 -7
  4. package/domain/index.d.ts +1 -1
  5. package/domain/index.mjs +115 -90
  6. package/domain/index.mjs.map +1 -1
  7. package/domain/plugin.d.ts +2 -2
  8. package/domain-server/agg.d.ts +1 -1
  9. package/domain-server/bind.d.ts +4 -1
  10. package/domain-server/event.d.ts +7 -7
  11. package/domain-server/index.d.ts +1 -1
  12. package/domain-server/index.mjs +115 -90
  13. package/domain-server/index.mjs.map +1 -1
  14. package/domain-server/plugin.d.ts +2 -2
  15. package/domain-shared/agg.d.ts +25 -0
  16. package/domain-shared/event.d.ts +19 -0
  17. package/domain-shared/index.d.ts +5 -0
  18. package/domain-shared/index.mjs +280 -0
  19. package/domain-shared/index.mjs.map +1 -0
  20. package/domain-shared/type.d.ts +73 -0
  21. package/{index-Dhhr_iXc.js → index-BcykEFlB.js} +3 -3
  22. package/{index-Dhhr_iXc.js.map → index-BcykEFlB.js.map} +1 -1
  23. package/package.json +1 -1
  24. package/timer/index.d.ts +9 -1
  25. package/timer/index.mjs +42 -27
  26. package/timer/index.mjs.map +1 -1
  27. package/pure-domain/agg.d.ts +0 -0
  28. package/pure-domain/event.d.ts +0 -42
  29. package/pure-domain/index.d.ts +0 -0
  30. package/pure-domain/index.mjs +0 -2
  31. package/pure-domain/index.mjs.map +0 -1
  32. package/pure-domain/state.d.ts +0 -7
  33. package/shared-domain/index.d.ts +0 -19
  34. package/shared-domain/index.mjs +0 -59
  35. package/shared-domain/index.mjs.map +0 -1
  36. package/shared-domain/package.json +0 -5
  37. /package/{shared-domain → domain-shared}/common.d.ts +0 -0
  38. /package/{pure-domain → domain-shared}/package.json +0 -0
package/domain/agg.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type DeepReadonly, type EffectScope, type ComputedRef } from 'vue';
1
+ import { type ComputedRef, type DeepReadonly, type EffectScope } from 'vue';
2
2
  import { type DomainBroadcastEvent, type DomainDestroyedEventApi, type DomainEvent, type DomainRequestEvent } from './event';
3
3
  type AddDestroyedEventApi<T extends object, K = 'destroyed'> = keyof T extends never ? {
4
4
  destroyed: DomainDestroyedEventApi;
package/domain/bind.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Ref, ShallowRef, Reactive, ShallowReactive, WatchCallback, WatchOptions } from 'vue';
1
+ import { type Reactive, type Ref, type ShallowRef, type ShallowReactive, type WatchCallback, type WatchOptions } from 'vue';
2
2
  type DomainAggState = DomainAggRefState | DomainAggReactiveState;
3
3
  type DomainAggRefState = Readonly<Ref<any>> | Readonly<ShallowRef<any>>;
4
4
  type DomainAggReactiveState = Readonly<Reactive<object>> | Readonly<ShallowReactive<object>>;
@@ -10,4 +10,7 @@ type InferValue<T> = T extends () => infer R ? R : T extends Readonly<Ref<any>>
10
10
  export declare function bindRef<STATE extends DomainAggState | SingleFieldRef, T extends InferValue<STATE>>(aggState: STATE, onChange: WatchCallback<T>, watchOptions?: WatchOptions & {
11
11
  forceSync?: boolean;
12
12
  }): Ref<T>;
13
+ export declare function bindReactive<STATE extends DomainAggReactiveState, T extends InferValue<STATE> & object>(aggState: STATE, onChange: WatchCallback<T>, watchOptions?: WatchOptions & {
14
+ forceSync?: boolean;
15
+ }): Reactive<T>;
13
16
  export {};
package/domain/event.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { DeepReadonly, UnwrapNestedRefs } from 'vue';
1
+ import type { DeepReadonly, UnwrapNestedRefs } from 'vue';
2
2
  export type DomainRequestEventOptions<DATA, ON_REPLY extends (data: any) => void> = {
3
3
  dataType?: DATA;
4
4
  onReply: ON_REPLY;
@@ -11,19 +11,19 @@ export type DomainRequestEvent<DATA, REPLY_DATA> = {
11
11
  listeners: DomainRequestEventListener<DATA, REPLY_DATA>[];
12
12
  publishRequest: (data: DeepReadonly<UnwrapNestedRefs<DATA>>) => Promise<REPLY_DATA>;
13
13
  api: {
14
- latestVersion: Readonly<string>;
14
+ readonly latestVersion: string;
15
15
  listenAndReply: (replyFn: DomainRequestEventListener<DATA, REPLY_DATA>) => () => void;
16
16
  };
17
17
  };
18
18
  export type DomainRequestEventListener<DATA, REPLY_DATA> = (param: {
19
- data: DeepReadonly<UnwrapNestedRefs<DATA>>;
20
- version: string;
19
+ readonly data: DeepReadonly<UnwrapNestedRefs<DATA>>;
20
+ readonly version: string;
21
21
  }) => REPLY_DATA;
22
22
  export type DomainBroadcastEvent<DATA> = {
23
23
  listeners: DomainBroadcastEventListener<DATA>[];
24
24
  publish: (data: DeepReadonly<UnwrapNestedRefs<DATA>>) => void;
25
25
  api: {
26
- latestVersion: Readonly<string>;
26
+ readonly latestVersion: string;
27
27
  listen: (cb: (event: {
28
28
  data: DeepReadonly<UnwrapNestedRefs<DATA>>;
29
29
  version: string;
@@ -31,8 +31,8 @@ export type DomainBroadcastEvent<DATA> = {
31
31
  };
32
32
  };
33
33
  export type DomainBroadcastEventListener<DATA> = (param: {
34
- data: DeepReadonly<UnwrapNestedRefs<DATA>>;
35
- version: string;
34
+ readonly data: DeepReadonly<UnwrapNestedRefs<DATA>>;
35
+ readonly version: string;
36
36
  }) => void;
37
37
  export type DomainDestroyedEventApi = DomainBroadcastEvent<{}>['api'];
38
38
  export type DomainEvent<DATA, REPLY_DATA> = DomainRequestEvent<DATA, REPLY_DATA> | DomainBroadcastEvent<DATA>;
package/domain/index.d.ts CHANGED
@@ -4,5 +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 } from './bind';
7
+ export { bindRef, bindReactive } from './bind';
8
8
  export * as Utils from './common';
package/domain/index.mjs CHANGED
@@ -1,33 +1,33 @@
1
- import { t as h } from "../index-Dhhr_iXc.js";
2
- import { ref as z, computed as g, effectScope as x, onScopeDispose as P, shallowReadonly as w, readonly as S, watch as E, isReactive as R, isRef as O, unref as T } from "vue";
3
- function B() {
1
+ import { t as z } from "../index-BcykEFlB.js";
2
+ import { ref as S, computed as E, effectScope as P, onScopeDispose as R, shallowReadonly as I, readonly as h, watch as v, reactive as T, isReactive as D, isRef as C, unref as N } from "vue";
3
+ function F() {
4
4
  function e(t) {
5
5
  let o = "0", i = [];
6
6
  const r = [];
7
- function c(s, u, a, p) {
8
- const f = A(o);
9
- o = f, i.push({
10
- version: f,
7
+ function c(s, u, f, p) {
8
+ const a = A(o);
9
+ o = a, i.push({
10
+ version: a,
11
11
  data: s,
12
12
  resolve: u,
13
- reject: a,
13
+ reject: f,
14
14
  timerId: p
15
15
  }), n();
16
16
  }
17
17
  function n() {
18
18
  if (!(i.length === 0 || r.length === 0))
19
19
  for (const s of i) {
20
- const { version: u, data: a, resolve: p, reject: f, timerId: d } = s, m = {
21
- data: a,
20
+ const { version: u, data: f, resolve: p, reject: a, timerId: d } = s, m = {
21
+ data: f,
22
22
  version: u
23
23
  };
24
- for (const v of r)
24
+ for (const w of r)
25
25
  try {
26
- const l = v(m);
26
+ const l = w(m);
27
27
  t.onReply(l), p(l), d && clearTimeout(d);
28
28
  } catch (l) {
29
29
  if (t.onError && l instanceof Error)
30
- t.onError(l), t.isTerminateOnError && (f(l), d && clearTimeout(d));
30
+ t.onError(l), t.isTerminateOnError && (a(l), d && clearTimeout(d));
31
31
  else
32
32
  throw new Error("caught a unknown error" + (l?.toString() || l));
33
33
  }
@@ -37,11 +37,11 @@ function B() {
37
37
  return {
38
38
  listeners: r,
39
39
  async publishRequest(s) {
40
- const u = new h.Deferred();
41
- let a;
42
- return t.timeoutMs && (a = setTimeout(() => {
40
+ const u = new z.Deferred();
41
+ let f;
42
+ return t.timeoutMs && (f = setTimeout(() => {
43
43
  u.reject(new Error(`timeout: ${t.timeoutMs} ms`));
44
- }, t.timeoutMs)), c(s, u.resolve, u.reject, a), await u.promise;
44
+ }, t.timeoutMs)), c(s, u.resolve, u.reject, f), await u.promise;
45
45
  },
46
46
  api: {
47
47
  get latestVersion() {
@@ -62,7 +62,7 @@ function B() {
62
62
  options: e
63
63
  };
64
64
  }
65
- function D() {
65
+ function O() {
66
66
  let e = "0";
67
67
  const t = [];
68
68
  return {
@@ -96,12 +96,12 @@ function A(e) {
96
96
  const i = Math.max(t.length, o.length);
97
97
  let r = 0, c = [];
98
98
  for (let n = 0; n < i; n++) {
99
- const s = n < t.length ? parseInt(t[n], 10) : 0, u = n < o.length ? parseInt(o[n], 10) : 0, a = s + u + r;
100
- c.push(a % 10), r = Math.floor(a / 10);
99
+ const s = n < t.length ? parseInt(t[n], 10) : 0, u = n < o.length ? parseInt(o[n], 10) : 0, f = s + u + r;
100
+ c.push(f % 10), r = Math.floor(f / 10);
101
101
  }
102
102
  return r > 0 && c.push(r), c.reverse().join("");
103
103
  }
104
- function I(e = "") {
104
+ function g(e = "") {
105
105
  const t = Date.now().toString(36), o = Math.random().toString(36).substring(2, 10);
106
106
  return `${e}${t}${o}`;
107
107
  }
@@ -169,10 +169,10 @@ function _(e, t = /* @__PURE__ */ new WeakMap()) {
169
169
  o[i] = _(e[i], t);
170
170
  return o;
171
171
  }
172
- const F = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
172
+ const L = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
173
173
  __proto__: null,
174
174
  deepClone: _,
175
- genId: I,
175
+ genId: g,
176
176
  isEqual: y
177
177
  }, Symbol.toStringTag, { value: "Module" }));
178
178
  function k(e) {
@@ -195,11 +195,11 @@ function k(e) {
195
195
  });
196
196
  for (const u of Object.values(o))
197
197
  u.mount({ api: n.api, __aggId: n.__id }), s.push(u.__id);
198
- if (i.set(n, s), C(n)) {
198
+ if (i.set(n, s), b(n)) {
199
199
  const u = n.api.events.destroyed.listen(() => {
200
200
  delete r[n.__id], e?.(n);
201
- for (const a of c)
202
- a(n);
201
+ for (const f of c)
202
+ f(n);
203
203
  u?.();
204
204
  });
205
205
  }
@@ -210,7 +210,7 @@ function k(e) {
210
210
  createSetupPlugin(n) {
211
211
  let s;
212
212
  return n instanceof Function ? s = n() : s = n, Object.freeze({
213
- __id: I(),
213
+ __id: g(),
214
214
  type: "Setup",
215
215
  mount(u) {
216
216
  if (u.isInitialized.value)
@@ -222,7 +222,7 @@ function k(e) {
222
222
  createHotSwapPlugin(n) {
223
223
  let s;
224
224
  return n instanceof Function ? s = n() : s = n, Object.freeze({
225
- __id: I(),
225
+ __id: g(),
226
226
  type: "HotSwap",
227
227
  mount: s.mount,
228
228
  unmount: s.unmount
@@ -264,21 +264,21 @@ function k(e) {
264
264
  }
265
265
  });
266
266
  }
267
- function L(e, t) {
267
+ function q(e, t) {
268
268
  return k(t);
269
269
  }
270
- function q(e) {
270
+ function K(e) {
271
271
  return k();
272
272
  }
273
- function C(e) {
273
+ function b(e) {
274
274
  return e.type === "MultiInstance";
275
275
  }
276
- function N(e) {
276
+ function H(e) {
277
277
  return j(e);
278
278
  }
279
- function H(e) {
279
+ function V(e) {
280
280
  const t = j(e);
281
- return w({
281
+ return I({
282
282
  states: t.states,
283
283
  commands: t.commands,
284
284
  events: t.events
@@ -287,24 +287,24 @@ function H(e) {
287
287
  function j(e) {
288
288
  const t = e.states;
289
289
  for (const n of Object.keys(e.states))
290
- t[n] = S(t[n]);
291
- const o = w(e.states), i = S(e.commands), r = {}, c = e.events;
290
+ t[n] = h(t[n]);
291
+ const o = I(e.states), i = h(e.commands), r = {}, c = e.events;
292
292
  for (const n in e.events)
293
293
  r[n] = c[n].api;
294
- return w({
294
+ return I({
295
295
  states: o,
296
296
  commands: i,
297
- events: w(r),
297
+ events: I(r),
298
298
  destroy: e.destroy
299
299
  });
300
300
  }
301
- function K(e, t) {
301
+ function W(e, t) {
302
302
  const {
303
303
  resolve: o,
304
304
  reject: i,
305
305
  promise: r
306
- } = new h.Deferred();
307
- let c = z(!1);
306
+ } = new z.Deferred();
307
+ let c = S(!1);
308
308
  function n(l) {
309
309
  if (c.value === !0)
310
310
  throw new Error("Agg already initialized");
@@ -318,41 +318,41 @@ function K(e, t) {
318
318
  throw i(l), l;
319
319
  })
320
320
  );
321
- const u = x(), a = u.run(
321
+ const u = P(), f = u.run(
322
322
  () => t({
323
323
  getCurrentScope() {
324
324
  return u;
325
325
  },
326
- onScopeDispose: P,
326
+ onScopeDispose: R,
327
327
  onCreated(l) {
328
328
  Promise.resolve().then(l);
329
329
  },
330
330
  onBeforeInitialize: n,
331
- isInitialized: g(() => c.value),
331
+ isInitialized: E(() => c.value),
332
332
  untilInitialized: r
333
333
  })
334
- ), p = a.states || {}, f = a.commands || {}, d = a.events || {};
334
+ ), p = f.states || {}, a = f.commands || {}, d = f.events || {};
335
335
  let m;
336
- d.destroyed ? m = d.destroyed : (m = D(), d.destroyed = m);
337
- let v = a.destroy;
338
- return v || (v = () => {
336
+ d.destroyed ? m = d.destroyed : (m = O(), d.destroyed = m);
337
+ let w = f.destroy;
338
+ return w || (w = (() => {
339
339
  m?.publish({});
340
340
  for (const l in d) {
341
- const M = d[l];
342
- M.listeners.length = 0;
341
+ const x = d[l];
342
+ x.listeners.length = 0;
343
343
  }
344
344
  u.stop();
345
- }), w({
346
- __id: I(),
345
+ })), I({
346
+ __id: g(),
347
347
  type: "MultiInstance",
348
348
  id: e,
349
- api: N({
349
+ api: H({
350
350
  states: p,
351
- commands: f,
351
+ commands: a,
352
352
  events: d,
353
- destroy: v
353
+ destroy: w
354
354
  }),
355
- isInitialized: g(() => c.value),
355
+ isInitialized: E(() => c.value),
356
356
  async untilInitialized() {
357
357
  return await r.catch((l) => {
358
358
  throw new Error(`Failed to initialize Agg: ${l.message}
@@ -361,67 +361,67 @@ Stack : ${l.stack || "unkown"}`);
361
361
  }
362
362
  });
363
363
  }
364
- function W(e) {
364
+ function G(e) {
365
365
  const {
366
366
  resolve: t,
367
367
  reject: o,
368
368
  promise: i
369
- } = new h.Deferred();
370
- let r = z(!1);
371
- function c(f) {
369
+ } = new z.Deferred();
370
+ let r = S(!1);
371
+ function c(a) {
372
372
  if (r.value === !0)
373
373
  throw new Error("Agg already initialized");
374
- n.push(f());
374
+ n.push(a());
375
375
  }
376
376
  const n = [], s = e({
377
- onCreated(f) {
378
- Promise.resolve().then(f);
377
+ onCreated(a) {
378
+ Promise.resolve().then(a);
379
379
  },
380
380
  onBeforeInitialize: c,
381
- isInitialized: g(() => r.value),
381
+ isInitialized: E(() => r.value),
382
382
  untilInitialized: i
383
383
  });
384
384
  setTimeout(
385
385
  () => Promise.all(n).then(() => {
386
386
  t(), r.value = !0;
387
- }).catch((f) => {
388
- o(f);
387
+ }).catch((a) => {
388
+ o(a);
389
389
  }),
390
390
  0
391
391
  );
392
- const u = s.states || {}, a = s.commands || {}, p = s.events || {};
392
+ const u = s.states || {}, f = s.commands || {}, p = s.events || {};
393
393
  return {
394
- __id: I(),
394
+ __id: g(),
395
395
  type: "Singleton",
396
- api: H({
396
+ api: V({
397
397
  states: u,
398
- commands: a,
398
+ commands: f,
399
399
  events: p,
400
400
  destroy: () => {
401
401
  }
402
402
  }),
403
- isInitialized: g(() => r.value),
403
+ isInitialized: E(() => r.value),
404
404
  async untilInitialized() {
405
- return await i.catch((f) => {
406
- throw new Error(`Failed to initialize Agg: ${f.message}
407
- Stack : ${f.stack || "unkown"}`);
405
+ return await i.catch((a) => {
406
+ throw new Error(`Failed to initialize Agg: ${a.message}
407
+ Stack : ${a.stack || "unkown"}`);
408
408
  });
409
409
  }
410
410
  };
411
411
  }
412
- function G(e, t, o) {
413
- const i = z(V(e));
412
+ function U(e, t, o) {
413
+ const i = S(M(e));
414
414
  if (!o?.forceSync)
415
- return E(i, t, o), i;
415
+ return v(i, t, o), i;
416
416
  o.forceSync = void 0;
417
417
  let r;
418
- return E(
418
+ return v(
419
419
  e,
420
420
  (c) => {
421
421
  r = c, i.value = c;
422
422
  },
423
423
  o
424
- ), E(
424
+ ), v(
425
425
  i,
426
426
  (c, n, s) => {
427
427
  y(c, r) || t(c, n, s);
@@ -429,24 +429,49 @@ function G(e, t, o) {
429
429
  o
430
430
  ), i;
431
431
  }
432
- function V(e) {
432
+ function X(e, t, o) {
433
+ const i = T(M(e));
434
+ if (!o?.forceSync)
435
+ return v(i, t, o), i;
436
+ o.forceSync = void 0;
437
+ let r = !1;
438
+ return v(
439
+ e,
440
+ (c) => {
441
+ r = !0;
442
+ const n = Object.keys(c);
443
+ for (const s of n)
444
+ i[s] = c[s];
445
+ r = !1;
446
+ },
447
+ o
448
+ ), v(
449
+ i,
450
+ (c, n, s) => {
451
+ r || t(c, n, s);
452
+ },
453
+ o
454
+ ), i;
455
+ }
456
+ function M(e) {
433
457
  let t;
434
458
  if (typeof e == "function")
435
459
  t = e();
436
- else if (R(e) || O(e))
437
- t = T(e);
460
+ else if (D(e) || C(e))
461
+ t = N(e);
438
462
  else
439
463
  throw new Error("invalid state");
440
464
  return typeof t == "object" && (t = _(t)), t;
441
465
  }
442
466
  export {
443
- F as Utils,
444
- G as bindRef,
445
- D as createBroadcastEvent,
446
- K as createMultiInstanceAgg,
447
- q as createPluginHelperByAgg,
448
- L as createPluginHelperByAggCreator,
449
- B as createRequestEvent,
450
- W as createSingletonAgg
467
+ L as Utils,
468
+ X as bindReactive,
469
+ U as bindRef,
470
+ O as createBroadcastEvent,
471
+ W as createMultiInstanceAgg,
472
+ K as createPluginHelperByAgg,
473
+ q as createPluginHelperByAggCreator,
474
+ F as createRequestEvent,
475
+ G as createSingletonAgg
451
476
  };
452
477
  //# sourceMappingURL=index.mjs.map