@ng-org/alien-deepsignals 0.1.2-alpha.5 → 0.1.2-alpha.7

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 (62) hide show
  1. package/README.md +55 -374
  2. package/dist/core.d.ts +66 -60
  3. package/dist/core.d.ts.map +1 -1
  4. package/dist/core.js +70 -82
  5. package/dist/deepSignal.d.ts +19 -5
  6. package/dist/deepSignal.d.ts.map +1 -1
  7. package/dist/deepSignal.js +214 -141
  8. package/dist/effect.d.ts.map +1 -1
  9. package/dist/effect.js +8 -1
  10. package/dist/hooks/react/useDeepSignal.d.ts +1 -1
  11. package/dist/hooks/react/useDeepSignal.d.ts.map +1 -1
  12. package/dist/hooks/react/useDeepSignal.js +5 -2
  13. package/dist/hooks/svelte/index.d.ts +0 -1
  14. package/dist/hooks/svelte/index.d.ts.map +1 -1
  15. package/dist/hooks/svelte/useDeepSignal.svelte.d.ts +3 -15
  16. package/dist/hooks/svelte/useDeepSignal.svelte.d.ts.map +1 -1
  17. package/dist/hooks/svelte/useDeepSignal.svelte.js +29 -63
  18. package/dist/hooks/svelte4/index.d.ts +4 -0
  19. package/dist/hooks/svelte4/index.d.ts.map +1 -0
  20. package/dist/hooks/svelte4/index.js +8 -0
  21. package/dist/hooks/svelte4/useDeepSignal.svelte.d.ts +27 -0
  22. package/dist/hooks/svelte4/useDeepSignal.svelte.d.ts.map +1 -0
  23. package/dist/hooks/svelte4/useDeepSignal.svelte.js +91 -0
  24. package/dist/hooks/vue/useDeepSignal.d.ts +2 -2
  25. package/dist/hooks/vue/useDeepSignal.d.ts.map +1 -1
  26. package/dist/hooks/vue/useDeepSignal.js +22 -74
  27. package/dist/index.d.ts +1 -2
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +8 -2
  30. package/dist/test/frontend/astro-app/src/components/ReactPanel.d.ts.map +1 -1
  31. package/dist/test/frontend/astro-app/src/components/{ReactPanel.js → ReactPanel.jsx} +56 -45
  32. package/dist/test/frontend/playwright/crossFrameworkHooks.spec.js +13 -3
  33. package/dist/test/frontend/utils/mockData.d.ts.map +1 -1
  34. package/dist/test/frontend/utils/mockData.js +13 -4
  35. package/dist/test/lib/index.test.js +16 -3
  36. package/dist/test/lib/misc.test.js +104 -1
  37. package/dist/test/lib/watch.test.js +2 -11
  38. package/dist/types.d.ts +94 -19
  39. package/dist/types.d.ts.map +1 -1
  40. package/dist/types.js +9 -0
  41. package/dist/watch.d.ts +37 -0
  42. package/dist/watch.d.ts.map +1 -1
  43. package/dist/watch.js +35 -0
  44. package/package.json +8 -5
  45. package/dist/test/frontend/astro-app/src/components/PerfSuiteClient.d.ts +0 -4
  46. package/dist/test/frontend/astro-app/src/components/PerfSuiteClient.d.ts.map +0 -1
  47. package/dist/test/frontend/astro-app/src/components/PerfSuiteClient.js +0 -225
  48. package/dist/test/frontend/astro-app/src/components/perf/react/ReactPerfDeep.d.ts +0 -4
  49. package/dist/test/frontend/astro-app/src/components/perf/react/ReactPerfDeep.d.ts.map +0 -1
  50. package/dist/test/frontend/astro-app/src/components/perf/react/ReactPerfDeep.js +0 -150
  51. package/dist/test/frontend/astro-app/src/components/perf/react/ReactPerfNative.d.ts +0 -4
  52. package/dist/test/frontend/astro-app/src/components/perf/react/ReactPerfNative.d.ts.map +0 -1
  53. package/dist/test/frontend/astro-app/src/components/perf/react/ReactPerfNative.js +0 -184
  54. package/dist/test/frontend/playwright/perfSuite.spec.d.ts +0 -2
  55. package/dist/test/frontend/playwright/perfSuite.spec.d.ts.map +0 -1
  56. package/dist/test/frontend/playwright/perfSuite.spec.js +0 -128
  57. package/dist/test/frontend/utils/perfScenarios.d.ts +0 -15
  58. package/dist/test/frontend/utils/perfScenarios.d.ts.map +0 -1
  59. package/dist/test/frontend/utils/perfScenarios.js +0 -287
  60. package/dist/test/lib/core.test.d.ts +0 -2
  61. package/dist/test/lib/core.test.d.ts.map +0 -1
  62. package/dist/test/lib/core.test.js +0 -53
package/dist/core.js CHANGED
@@ -9,105 +9,93 @@
9
9
  // according to those terms.
10
10
  // SPDX-License-Identifier: Apache-2.0 OR MIT
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.isSignal = exports.computed = exports.signal = exports._rawEffect = exports._rawSetCurrentSub = exports._rawGetCurrentSub = exports._rawEndBatch = exports._rawStartBatch = exports._rawComputed = exports._rawSignal = void 0;
12
+ exports.effect = exports.alienSignal = exports.computed = void 0;
13
13
  exports.batch = batch;
14
- /** Lightweight facade adding ergonomic helpers (.value/.peek/.get/.set) to native alien-signals function signals. */
15
- // Native re-exports for advanced usage.
16
- var alien_signals_1 = require("alien-signals");
17
- Object.defineProperty(exports, "_rawSignal", { enumerable: true, get: function () { return alien_signals_1.signal; } });
18
- Object.defineProperty(exports, "_rawComputed", { enumerable: true, get: function () { return alien_signals_1.computed; } });
19
- Object.defineProperty(exports, "_rawStartBatch", { enumerable: true, get: function () { return alien_signals_1.startBatch; } });
20
- Object.defineProperty(exports, "_rawEndBatch", { enumerable: true, get: function () { return alien_signals_1.endBatch; } });
21
- Object.defineProperty(exports, "_rawGetCurrentSub", { enumerable: true, get: function () { return alien_signals_1.getCurrentSub; } });
22
- Object.defineProperty(exports, "_rawSetCurrentSub", { enumerable: true, get: function () { return alien_signals_1.setCurrentSub; } });
23
- Object.defineProperty(exports, "_rawEffect", { enumerable: true, get: function () { return alien_signals_1.effect; } });
24
- const alien_signals_2 = require("alien-signals");
25
- const contents_1 = require("./contents");
26
- /**
27
- * Decorate a native signal function with helpers & identity.
28
- */
29
- function tagSignal(fn) {
30
- Object.defineProperty(fn, contents_1.ReactiveFlags.IS_SIGNAL, { value: true });
31
- Object.defineProperty(fn, "value", {
32
- get: () => fn(),
33
- set: (v) => fn(v),
34
- });
35
- // Add peek to mirror old API (non-tracking read)
36
- if (!fn.peek)
37
- Object.defineProperty(fn, "peek", { value: () => fn() });
38
- if (!fn.get)
39
- Object.defineProperty(fn, "get", { value: () => fn() });
40
- if (!fn.set)
41
- Object.defineProperty(fn, "set", { value: (v) => fn(v) });
42
- return fn;
43
- }
44
- /**
45
- * Decorate a native computed function with ergonomic helpers & readonly value accessor.
46
- */
47
- function tagComputed(fn) {
48
- Object.defineProperty(fn, contents_1.ReactiveFlags.IS_SIGNAL, { value: true });
49
- Object.defineProperty(fn, "value", { get: () => fn() });
50
- if (!fn.peek)
51
- Object.defineProperty(fn, "peek", { value: () => fn() });
52
- if (!fn.get)
53
- Object.defineProperty(fn, "get", { value: () => fn() });
54
- return fn;
55
- }
56
- /**
57
- * Create a new writable function-form signal enhanced with `.value`, `.peek()`, `.get()`, `.set()`.
58
- *
59
- * @example
60
- * const count = signal(0);
61
- * count(); // 0 (track)
62
- * count(1); // write
63
- * count.value; // 1 (track)
64
- * count.peek(); // 1 (non-tracking)
65
- */
66
- const signal = (v) => tagSignal((0, alien_signals_2.signal)(v));
67
- exports.signal = signal;
68
- /**
69
- * Create a lazy computed (readonly) signal derived from other signals.
70
- *
71
- * Computed signals are automatically cached and only recompute when their tracked
72
- * dependencies change. The getter function is evaluated lazily—if you never read
73
- * the computed value, the computation never runs.
74
- *
75
- * The returned function can be called directly `computed()` or accessed via `.value`.
76
- * Use `.peek()` for non-tracking reads (won't establish reactive dependency).
77
- *
78
- * @example
79
- * const count = signal(5);
80
- * const doubled = computed(() => count() * 2);
81
- * doubled(); // 10 (establishes dependency, caches result)
82
- * doubled.value; // 10 (cached, same as calling it)
83
- * doubled.peek(); // 10 (no dependency tracking)
84
- * count(10);
85
- * doubled(); // 20 (recomputed because count changed)
86
- */
87
- const computed = (getter) => tagComputed((0, alien_signals_2.computed)(getter));
88
- exports.computed = computed;
89
- /** Runtime guard that an unknown value is one of our tagged signals/computeds. */
90
- const isSignal = (s) => typeof s === "function" && !!s && !!s[contents_1.ReactiveFlags.IS_SIGNAL];
91
- exports.isSignal = isSignal;
14
+ const alien_signals_1 = require("alien-signals");
92
15
  /**
93
16
  * Execute multiple signal writes in a single batched update frame.
94
17
  * All downstream computed/effect re-evaluations are deferred until the function exits.
95
18
  *
96
- * IMPORTANT: The callback MUST be synchronous. If it returns a Promise the batch will
19
+ * IMPORTANT: The callback must be synchronous. If it returns a Promise the batch will
97
20
  * still end immediately after scheduling, possibly causing mid-async flushes.
98
21
  *
99
22
  * @example
23
+ * ```ts
100
24
  * batch(() => {
101
25
  * count(count() + 1);
102
26
  * other(other() + 2);
103
27
  * }); // effects observing both run only once
28
+ * ```
104
29
  */
105
30
  function batch(fn) {
106
- (0, alien_signals_2.startBatch)();
31
+ (0, alien_signals_1.startBatch)();
107
32
  try {
108
33
  return fn();
109
34
  }
110
35
  finally {
111
- (0, alien_signals_2.endBatch)();
36
+ (0, alien_signals_1.endBatch)();
112
37
  }
113
38
  }
39
+ /**
40
+ * Re-export of alien-signals computed function.
41
+ *
42
+ * Use the `computed()` function to create lazy derived signals that automatically
43
+ * track their dependencies and recompute only when needed.
44
+ *
45
+ * Key features:
46
+ * - **Lazy evaluation**: The computation runs only when you actually read the computed value.
47
+ * If you never access `fullName()`, the concatenation never happens—no wasted CPU cycles.
48
+ * - **Automatic caching**: Once computed, the result is cached until a dependency changes.
49
+ * Multiple reads return the cached value without re-running the getter.
50
+ * - **Fine-grained reactivity**: Only recomputes when its tracked dependencies change.
51
+ * Unrelated state mutations don't trigger unnecessary recalculation.
52
+ * - **Composable**: Computed signals can depend on other computed signals,
53
+ * forming efficient dependency chains.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { computed } from "@ng-org/alien-deepsignals";
58
+ *
59
+ * const state = deepSignal({
60
+ * firstName: "Ada",
61
+ * lastName: "Lovelace",
62
+ * items: [1, 2, 3],
63
+ * });
64
+ *
65
+ * // Create a computed signal that derives from reactive state
66
+ * const fullName = computed(() => `${state.firstName} ${state.lastName}`);
67
+ *
68
+ * console.log(fullName()); // "Ada Lovelace" - computes on first access
69
+ *
70
+ * state.firstName = "Grace";
71
+ * console.log(fullName()); // "Grace Lovelace" - recomputes automatically
72
+ *
73
+ * // Expensive computation only runs when accessed and dependencies change
74
+ * const expensiveResult = computed(() => {
75
+ * console.log("Computing...");
76
+ * return state.items.reduce((sum, n) => sum + n * n, 0);
77
+ * });
78
+ *
79
+ * // No computation happens yet!
80
+ * state.items.push(4);
81
+ * // Still no computation...
82
+ *
83
+ * console.log(expensiveResult()); // "Computing..." + result
84
+ * console.log(expensiveResult()); // Cached, no log
85
+ * state.items.push(5);
86
+ * console.log(expensiveResult()); // "Computing..." again (dependency changed)
87
+ *
88
+ * ```
89
+ */
90
+ exports.computed = alien_signals_1.computed;
91
+ /**
92
+ * Re-export of alien-signals `signal` function which creates a basic signal.
93
+ */
94
+ exports.alienSignal = alien_signals_1.signal;
95
+ /**
96
+ * Re-export of alien-signals effect function.
97
+ *
98
+ * Callback reruns on every signal modification that is used within its callback.
99
+ *
100
+ */
101
+ exports.effect = alien_signals_1.effect;
@@ -1,10 +1,15 @@
1
1
  import { DeepPatchJITSubscriber, DeepPatchSubscriber, DeepSignal, DeepSignalOptions } from "./types";
2
2
  /** Runtime guard that checks whether a value is a deepSignal proxy. */
3
- export declare function isDeepSignal(value: any): boolean;
3
+ export declare function isDeepSignal(value: unknown): value is DeepSignal<any>;
4
4
  /**
5
- * Create a deep reactive proxy for objects, arrays or Sets.
6
- * Returns the input itself, if it's a deepSignal already.
7
- * Throws if provided with unsupported input types.
5
+ * MAIN ENTRY POINT to create a deep reactive proxy for objects, arrays or Sets.
6
+ *
7
+ * If input is a deepSignal already and options are provided,
8
+ * the added subscriberFactories are joined with the existing ones
9
+ * and `replaceProxiesInBranchOnChange` is or-ed with the current value.
10
+ *
11
+ *
12
+ * @throws if provided with unsupported input types.
8
13
  */
9
14
  export declare function deepSignal<T extends object>(input: T, options?: DeepSignalOptions): DeepSignal<T>;
10
15
  /**
@@ -17,10 +22,19 @@ export declare function subscribeDeepMutations(root: object | symbol, cb: DeepPa
17
22
  export declare function getDeepSignalRootId(value: any): symbol | undefined;
18
23
  /** Retrieve the current patch version for a deepSignal root (if tracked). */
19
24
  export declare function getDeepSignalVersion(root: object | symbol): number | undefined;
20
- /** Mark an object so deepSignal skips proxying it (shallow boundary). */
25
+ /** Mark an object so deepSignal skips proxying it (shallow boundary).
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * import { shallow } from "alien-deepsignals";
30
+ * state.config = shallow({ huge: { blob: true } });
31
+ * ```
32
+ */
21
33
  export declare function shallow<T extends object>(obj: T): T;
22
34
  /** Force a specific synthetic ID to be used for a Set entry prior to insertion. */
23
35
  export declare function setSetEntrySyntheticId(obj: object, id: string | number): void;
24
36
  /** Convenience helper to add an entry to a proxied Set with a pre-defined synthetic ID. */
25
37
  export declare function addWithId<T>(set: Set<T>, entry: T, id: string | number): T;
38
+ /** Get the original, raw value of a deep signal. */
39
+ export declare function getRaw<T extends object>(value: T | DeepSignal<T>): any;
26
40
  //# sourceMappingURL=deepSignal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deepSignal.d.ts","sourceRoot":"","sources":["../src/deepSignal.ts"],"names":[],"mappings":"AAWA,OAAO,EAGH,sBAAsB,EACtB,mBAAmB,EACnB,UAAU,EACV,iBAAiB,EAMpB,MAAM,SAAS,CAAC;AA+qCjB,uEAAuE;AACvE,wBAAgB,YAAY,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAEhD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EACvC,KAAK,EAAE,CAAC,EACR,OAAO,CAAC,EAAE,iBAAiB,GAC5B,UAAU,CAAC,CAAC,CAAC,CAwBf;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAClC,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,EAAE,EAAE,mBAAmB,GAAG,sBAAsB,EAChD,gBAAgB,GAAE,OAAe,GAClC,MAAM,IAAI,CAoBZ;AAED,yEAAyE;AACzE,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,GAAG,GAAG,MAAM,GAAG,SAAS,CAElE;AAED,6EAA6E;AAC7E,wBAAgB,oB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