@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.
Files changed (47) hide show
  1. package/README.md +476 -0
  2. package/dist/contents.d.ts +6 -0
  3. package/dist/contents.d.ts.map +1 -0
  4. package/dist/contents.js +18 -0
  5. package/dist/core.d.ts +75 -0
  6. package/dist/core.d.ts.map +1 -0
  7. package/dist/core.js +113 -0
  8. package/dist/deepSignal.d.ts +26 -0
  9. package/dist/deepSignal.d.ts.map +1 -0
  10. package/dist/deepSignal.js +916 -0
  11. package/dist/effect.d.ts +5 -0
  12. package/dist/effect.d.ts.map +1 -0
  13. package/dist/effect.js +35 -0
  14. package/dist/hooks/react/index.d.ts +3 -0
  15. package/dist/hooks/react/index.d.ts.map +1 -0
  16. package/dist/hooks/react/index.js +8 -0
  17. package/dist/hooks/react/useDeepSignal.d.ts +14 -0
  18. package/dist/hooks/react/useDeepSignal.d.ts.map +1 -0
  19. package/dist/hooks/react/useDeepSignal.js +39 -0
  20. package/dist/hooks/svelte/index.d.ts +4 -0
  21. package/dist/hooks/svelte/index.d.ts.map +1 -0
  22. package/dist/hooks/svelte/index.js +8 -0
  23. package/dist/hooks/svelte/useDeepSignal.svelte.d.ts +31 -0
  24. package/dist/hooks/svelte/useDeepSignal.svelte.d.ts.map +1 -0
  25. package/dist/hooks/svelte/useDeepSignal.svelte.js +74 -0
  26. package/dist/hooks/vue/index.d.ts +3 -0
  27. package/dist/hooks/vue/index.d.ts.map +1 -0
  28. package/dist/hooks/vue/index.js +8 -0
  29. package/dist/hooks/vue/useDeepSignal.d.ts +15 -0
  30. package/dist/hooks/vue/useDeepSignal.d.ts.map +1 -0
  31. package/dist/hooks/vue/useDeepSignal.js +73 -0
  32. package/dist/index.d.ts +6 -0
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +21 -0
  35. package/dist/iteratorHelpers.d.ts +3 -0
  36. package/dist/iteratorHelpers.d.ts.map +1 -0
  37. package/dist/iteratorHelpers.js +38 -0
  38. package/dist/types.d.ts +107 -0
  39. package/dist/types.d.ts.map +1 -0
  40. package/dist/types.js +2 -0
  41. package/dist/utils.d.ts +17 -0
  42. package/dist/utils.d.ts.map +1 -0
  43. package/dist/utils.js +47 -0
  44. package/dist/watch.d.ts +27 -0
  45. package/dist/watch.d.ts.map +1 -0
  46. package/dist/watch.js +72 -0
  47. package/package.json +84 -0
@@ -0,0 +1,27 @@
1
+ import { DeepPatch, DeepSignal } from "./types";
2
+ export type RegisterCleanup = (cleanupFn: () => void) => void;
3
+ export interface WatchOptions {
4
+ /** True, if the callback should be run immediately after `watch` was called. @default false*/
5
+ immediate?: boolean;
6
+ /** True, if the watcher should be unsubscribed after the first event. @default false*/
7
+ once?: boolean;
8
+ /**
9
+ * If true, triggers watch callback instantly after changes to the signal object.
10
+ * Otherwise, changes are batched and the watch callback is triggered in a microtask.
11
+ * This is useful for frontends like React where modifications on the changed input in
12
+ * a separate (microtask) will cause the cursor in input elements to reset.
13
+ */
14
+ triggerInstantly?: boolean;
15
+ }
16
+ export interface WatchPatchEvent<T extends object> {
17
+ patches: DeepPatch[];
18
+ /** The version if `triggerInstantly` is not true. */
19
+ version?: number;
20
+ newValue: DeepSignal<T>;
21
+ }
22
+ export type WatchPatchCallback<T extends object> = (event: WatchPatchEvent<T>) => void;
23
+ export declare function watch<T extends object>(source: DeepSignal<T>, callback: WatchPatchCallback<T>, options?: WatchOptions): {
24
+ stopListening: () => void;
25
+ registerCleanup: RegisterCleanup;
26
+ };
27
+ //# sourceMappingURL=watch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../src/watch.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAkB,UAAU,EAAE,MAAM,SAAS,CAAC;AAEhE,MAAM,MAAM,eAAe,GAAG,CAAC,SAAS,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;AAE9D,MAAM,WAAW,YAAY;IACzB,8FAA8F;IAC9F,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,uFAAuF;IACvF,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,MAAM;IAC7C,OAAO,EAAE,SAAS,EAAE,CAAC;IACrB,qDAAqD;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;CAC3B;AAED,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,MAAM,IAAI,CAC/C,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,KACxB,IAAI,CAAC;AAEV,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,EAClC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EACrB,QAAQ,EAAE,kBAAkB,CAAC,CAAC,CAAC,EAC/B,OAAO,GAAE,YAAiB;;;EAiE7B"}
package/dist/watch.js ADDED
@@ -0,0 +1,72 @@
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.watch = watch;
13
+ const deepSignal_1 = require("./deepSignal");
14
+ function watch(source, callback, options = {}) {
15
+ if (!(0, deepSignal_1.isDeepSignal)(source)) {
16
+ throw new Error("watch() expects a deepSignal root proxy");
17
+ }
18
+ const rootId = (0, deepSignal_1.getDeepSignalRootId)(source);
19
+ if (!rootId)
20
+ throw new Error("Unable to resolve deepSignal root id");
21
+ let active = true;
22
+ let cleanup;
23
+ const { immediate, once } = options;
24
+ const registerCleanup = (fn) => {
25
+ cleanup = fn;
26
+ };
27
+ const runCleanup = () => {
28
+ if (!cleanup)
29
+ return;
30
+ try {
31
+ cleanup();
32
+ }
33
+ finally {
34
+ cleanup = undefined;
35
+ }
36
+ };
37
+ const stopListening = () => {
38
+ if (!active)
39
+ return;
40
+ active = false;
41
+ runCleanup();
42
+ unsubscribe();
43
+ };
44
+ const deliver = (batch) => {
45
+ if (!active)
46
+ return;
47
+ runCleanup();
48
+ const next = source;
49
+ callback({
50
+ patches: batch.patches,
51
+ version: batch.version,
52
+ newValue: next,
53
+ });
54
+ if (once)
55
+ stopListening();
56
+ };
57
+ const unsubscribe = (0, deepSignal_1.subscribeDeepMutations)(rootId, (batch) => {
58
+ if (!batch.patches.length)
59
+ return;
60
+ deliver(batch);
61
+ }, options.triggerInstantly);
62
+ if (immediate) {
63
+ deliver({
64
+ patches: [],
65
+ version: (0, deepSignal_1.getDeepSignalVersion)(rootId) ?? 0,
66
+ });
67
+ }
68
+ return {
69
+ stopListening,
70
+ registerCleanup,
71
+ };
72
+ }
package/package.json ADDED
@@ -0,0 +1,84 @@
1
+ {
2
+ "name": "@ng-org/alien-deepsignals",
3
+ "version": "0.1.2-alpha.1",
4
+ "private": false,
5
+ "authors": [
6
+ "Laurin Weger",
7
+ "CCherry07"
8
+ ],
9
+ "license": "MIT/Apache-2.0",
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "main": "dist/index.js",
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "description": "NextGraph adaptation of AlienDeepSignals - alien signals, but using regular JavaScript objects",
18
+ "exports": {
19
+ ".": {
20
+ "import": "./dist/index.mjs",
21
+ "require": "./dist/index.js"
22
+ },
23
+ "./react": {
24
+ "types": "./dist/hooks/react/index.d.ts",
25
+ "default": "./dist/hooks/react/index.js"
26
+ },
27
+ "./svelte": {
28
+ "types": "./dist/hooks/svelte/index.d.ts",
29
+ "default": "./dist/hooks/svelte/index.js"
30
+ },
31
+ "./vue": {
32
+ "types": "./dist/hooks/vue/index.d.ts",
33
+ "default": "./dist/hooks/vue/index.js"
34
+ }
35
+ },
36
+ "dependencies": {
37
+ "alien-signals": "^2.0.7"
38
+ },
39
+ "optionalDependencies": {
40
+ "react": "^19.0.0 || ^18.0.0",
41
+ "svelte": "^5.0.0",
42
+ "vue": "^3.0.0"
43
+ },
44
+ "devDependencies": {
45
+ "@astrojs/react": "^4.4.2",
46
+ "@astrojs/svelte": "^7.2.2",
47
+ "@astrojs/vue": "^5.1.3",
48
+ "@sveltejs/vite-plugin-svelte": "^6.2.1",
49
+ "@types/node": "^22.10.9",
50
+ "@types/react": "^19.2.7",
51
+ "@types/react-dom": "^19.2.2",
52
+ "@vitest/coverage-v8": "3.2.4",
53
+ "astro": "^5.16.1",
54
+ "@playwright/test": "^1.55.0",
55
+ "react-dom": "^19.0.0",
56
+ "react": "^19.0.0",
57
+ "svelte": "^5.1.9",
58
+ "typescript": "^5.4.3",
59
+ "vue": "^3.5.11",
60
+ "vitest": "^3.0.2"
61
+ },
62
+ "repository": {
63
+ "type": "git",
64
+ "url": "https://git.nextgraph.org/NextGraph/nextgraph-rs"
65
+ },
66
+ "keywords": [
67
+ "signal",
68
+ "signals",
69
+ "deepsignals",
70
+ "alien-signals",
71
+ "alien-deepsignals"
72
+ ],
73
+ "bugs": {
74
+ "url": "https://git.nextgraph.org/NextGraph/nextgraph-rs/issues"
75
+ },
76
+ "homepage": "https://nextgraph.org",
77
+ "scripts": {
78
+ "test": "vitest --coverage --dir src/test/lib",
79
+ "test:frontend": "playwright test src/test/frontend",
80
+ "build:ts": "tsc"
81
+ },
82
+ "module": "dist/index.mjs",
83
+ "types": "dist/index.d.ts"
84
+ }