@ng-org/alien-deepsignals 0.1.2-alpha.1
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/README.md +476 -0
- package/dist/contents.d.ts +6 -0
- package/dist/contents.d.ts.map +1 -0
- package/dist/contents.js +18 -0
- package/dist/core.d.ts +75 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +113 -0
- package/dist/deepSignal.d.ts +26 -0
- package/dist/deepSignal.d.ts.map +1 -0
- package/dist/deepSignal.js +916 -0
- package/dist/effect.d.ts +5 -0
- package/dist/effect.d.ts.map +1 -0
- package/dist/effect.js +35 -0
- package/dist/hooks/react/index.d.ts +3 -0
- package/dist/hooks/react/index.d.ts.map +1 -0
- package/dist/hooks/react/index.js +8 -0
- package/dist/hooks/react/useDeepSignal.d.ts +14 -0
- package/dist/hooks/react/useDeepSignal.d.ts.map +1 -0
- package/dist/hooks/react/useDeepSignal.js +39 -0
- package/dist/hooks/svelte/index.d.ts +4 -0
- package/dist/hooks/svelte/index.d.ts.map +1 -0
- package/dist/hooks/svelte/index.js +8 -0
- package/dist/hooks/svelte/useDeepSignal.svelte.d.ts +31 -0
- package/dist/hooks/svelte/useDeepSignal.svelte.d.ts.map +1 -0
- package/dist/hooks/svelte/useDeepSignal.svelte.js +74 -0
- package/dist/hooks/vue/index.d.ts +3 -0
- package/dist/hooks/vue/index.d.ts.map +1 -0
- package/dist/hooks/vue/index.js +8 -0
- package/dist/hooks/vue/useDeepSignal.d.ts +15 -0
- package/dist/hooks/vue/useDeepSignal.d.ts.map +1 -0
- package/dist/hooks/vue/useDeepSignal.js +73 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/iteratorHelpers.d.ts +3 -0
- package/dist/iteratorHelpers.d.ts.map +1 -0
- package/dist/iteratorHelpers.js +38 -0
- package/dist/types.d.ts +107 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/utils.d.ts +17 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +47 -0
- package/dist/watch.d.ts +27 -0
- package/dist/watch.d.ts.map +1 -0
- package/dist/watch.js +72 -0
- package/package.json +84 -0
package/dist/core.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2025 Laurin Weger, Par le Peuple, NextGraph.org developers
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
// Licensed under the Apache License, Version 2.0
|
|
5
|
+
// <LICENSE-APACHE2 or http://www.apache.org/licenses/LICENSE-2.0>
|
|
6
|
+
// or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>,
|
|
7
|
+
// at your option. All files in the project carrying such
|
|
8
|
+
// notice may not be copied, modified, or distributed except
|
|
9
|
+
// according to those terms.
|
|
10
|
+
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
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;
|
|
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;
|
|
92
|
+
/**
|
|
93
|
+
* Execute multiple signal writes in a single batched update frame.
|
|
94
|
+
* All downstream computed/effect re-evaluations are deferred until the function exits.
|
|
95
|
+
*
|
|
96
|
+
* IMPORTANT: The callback MUST be synchronous. If it returns a Promise the batch will
|
|
97
|
+
* still end immediately after scheduling, possibly causing mid-async flushes.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* batch(() => {
|
|
101
|
+
* count(count() + 1);
|
|
102
|
+
* other(other() + 2);
|
|
103
|
+
* }); // effects observing both run only once
|
|
104
|
+
*/
|
|
105
|
+
function batch(fn) {
|
|
106
|
+
(0, alien_signals_2.startBatch)();
|
|
107
|
+
try {
|
|
108
|
+
return fn();
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
(0, alien_signals_2.endBatch)();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DeepPatchJITSubscriber, DeepPatchSubscriber, DeepSignal, DeepSignalOptions } from "./types";
|
|
2
|
+
/** Runtime guard that checks whether a value is a deepSignal proxy. */
|
|
3
|
+
export declare function isDeepSignal(value: any): boolean;
|
|
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.
|
|
8
|
+
*/
|
|
9
|
+
export declare function deepSignal<T extends object>(input: T, options?: DeepSignalOptions): DeepSignal<T>;
|
|
10
|
+
/**
|
|
11
|
+
* Low-level function, you should probably use `watch` instead.
|
|
12
|
+
*
|
|
13
|
+
* Register a deep mutation subscriber for the provided root or proxy.
|
|
14
|
+
*/
|
|
15
|
+
export declare function subscribeDeepMutations(root: object | symbol, cb: DeepPatchSubscriber | DeepPatchJITSubscriber, triggerInstantly?: boolean): () => void;
|
|
16
|
+
/** Return the root identifier symbol for a deepSignal proxy (if any). */
|
|
17
|
+
export declare function getDeepSignalRootId(value: any): symbol | undefined;
|
|
18
|
+
/** Retrieve the current patch version for a deepSignal root (if tracked). */
|
|
19
|
+
export declare function getDeepSignalVersion(root: object | symbol): number | undefined;
|
|
20
|
+
/** Mark an object so deepSignal skips proxying it (shallow boundary). */
|
|
21
|
+
export declare function shallow<T extends object>(obj: T): T;
|
|
22
|
+
/** Force a specific synthetic ID to be used for a Set entry prior to insertion. */
|
|
23
|
+
export declare function setSetEntrySyntheticId(obj: object, id: string | number): void;
|
|
24
|
+
/** Convenience helper to add an entry to a proxied Set with a pre-defined synthetic ID. */
|
|
25
|
+
export declare function addWithId<T>(set: Set<T>, entry: T, id: string | number): T;
|
|
26
|
+
//# sourceMappingURL=deepSignal.d.ts.map
|
|
@@ -0,0 +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;AAi/BjB,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,oBAAoB,CAChC,IAAI,EAAE,MAAM,GAAG,MAAM,GACtB,MAAM,GAAG,SAAS,CAIpB;AAED,yEAAyE;AACzE,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAGnD;AAED,mFAAmF;AACnF,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,QAGtE;AAED,2FAA2F;AAC3F,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,CAa1E"}
|