@solidjs/signals 2.0.0-beta.24 → 2.0.0-beta.26

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.
@@ -12,14 +12,14 @@ import "../core/effect.js";
12
12
 
13
13
  import { createMemo } from "../signals.js";
14
14
 
15
- import { ownEnumerableKeys, $PROXY, isWrappable, $TARGET, trackSelf, witnessAffectsMark, mergedOverlay, STORE_VALUE, storeLookup, STORE_LOOKUP, $DELETED, wrap, getStoreSymbols, getPropertyDescriptor, getStoreKeys, getKeys, $TRACK } from "./store.js";
15
+ import { ownEnumerableKeys, $PROXY, isWrappable, $TARGET, lookupTarget, trackSelf, witnessAffectsMark, mergedOverlay, STORE_VALUE, storeLookup, STORE_LOOKUP, $DELETED, wrap, getStoreSymbols, getPropertyDescriptor, getStoreKeys, getKeys, $TRACK, rawValuesUsed, isRawValue } from "./store.js";
16
16
 
17
17
  function snapshotImpl(e, t, r, n) {
18
18
  let o, s, i, c, f, u;
19
19
  if (!isWrappable(e)) return e;
20
20
  if (r && r.has(e)) return r.get(e);
21
21
  if (!r) r = new Map;
22
- if (o = e[$TARGET] || n?.get(e)?.[$TARGET]) {
22
+ if (o = e[$TARGET] || lookupTarget(e, n)) {
23
23
  if (t) {
24
24
  trackSelf(o, $TRACK);
25
25
  // A tracked walk reads THROUGH the record without touching the proxy
@@ -49,24 +49,24 @@ function snapshotImpl(e, t, r, n) {
49
49
  }
50
50
  if (s) {
51
51
  const s = i?.length ?? e.length;
52
- for (let p = 0; p < s; p++) {
53
- u = i && p in i ? i[p] : e[p];
52
+ for (let a = 0; a < s; a++) {
53
+ u = i && a in i ? i[a] : e[a];
54
54
  if (u === $DELETED) continue;
55
- if (t && isWrappable(u)) wrap(u, o);
55
+ if (t && isWrappable(u) && !(rawValuesUsed && isRawValue(u))) wrap(u, o);
56
56
  if ((f = snapshotImpl(u, t, r, n)) !== u || c) {
57
57
  if (!c) r.set(e, c = [ ...e ]);
58
- c[p] = f;
58
+ c[a] = f;
59
59
  }
60
60
  }
61
61
  // Enumerate array symbols separately to avoid scanning indices twice.
62
62
  // Spread copies omit symbols, so assign them after the numeric walk.
63
- const p = n ? getStoreSymbols(e, i) : [];
64
- for (let s = 0, l = p.length; s < l; s++) {
65
- const l = p[s];
66
- const a = getPropertyDescriptor(e, i, l);
67
- if (!a || a.get) continue;
63
+ const a = n ? getStoreSymbols(e, i) : [];
64
+ for (let s = 0, l = a.length; s < l; s++) {
65
+ const l = a[s];
66
+ const p = getPropertyDescriptor(e, i, l);
67
+ if (!p || p.get) continue;
68
68
  u = i && l in i ? i[l] : e[l];
69
- if (t && isWrappable(u)) wrap(u, o);
69
+ if (t && isWrappable(u) && !(rawValuesUsed && isRawValue(u))) wrap(u, o);
70
70
  f = snapshotImpl(u, t, r, n);
71
71
  if (f !== u || c) {
72
72
  if (!c) r.set(e, c = Object.assign([ ...e ], e));
@@ -83,30 +83,30 @@ function snapshotImpl(e, t, r, n) {
83
83
  // A lookup means this object belongs to an immutable store backing tree,
84
84
  // even if that nested value has not needed its own proxy yet.
85
85
  const s = n ? getStoreKeys(e, undefined) : getKeys(e, undefined);
86
- for (let i = 0, p = s.length; i < p; i++) {
87
- const p = s[i];
88
- const l = Object.getOwnPropertyDescriptor(e, p);
86
+ for (let i = 0, a = s.length; i < a; i++) {
87
+ const a = s[i];
88
+ const l = Object.getOwnPropertyDescriptor(e, a);
89
89
  if (l.get) continue;
90
90
  u = l.value;
91
- if (t && isWrappable(u)) wrap(u, o);
91
+ if (t && isWrappable(u) && !(rawValuesUsed && isRawValue(u))) wrap(u, o);
92
92
  if ((f = snapshotImpl(u, t, r, n)) !== u || c) {
93
93
  if (!c) {
94
94
  c = Object.create(Object.getPrototypeOf(e));
95
95
  Object.assign(c, e);
96
96
  }
97
- c[p] = f;
97
+ c[a] = f;
98
98
  }
99
99
  }
100
100
  } else {
101
101
  // An override only exists on a store record, and the target branch above
102
102
  // always set `lookup` alongside it — so this branch is always store-keyed.
103
103
  const s = getStoreKeys(e, i);
104
- for (let p = 0, l = s.length; p < l; p++) {
105
- let l = s[p];
106
- const a = getPropertyDescriptor(e, i, l);
107
- if (a.get) continue;
104
+ for (let a = 0, l = s.length; a < l; a++) {
105
+ let l = s[a];
106
+ const p = getPropertyDescriptor(e, i, l);
107
+ if (p.get) continue;
108
108
  u = l in i ? i[l] : e[l];
109
- if (t && isWrappable(u)) wrap(u, o);
109
+ if (t && isWrappable(u) && !(rawValuesUsed && isRawValue(u))) wrap(u, o);
110
110
  if ((f = snapshotImpl(u, t, r, n)) !== e[l] || c) {
111
111
  if (!c) {
112
112
  c = Object.create(Object.getPrototypeOf(e));
@@ -3,6 +3,7 @@ import type { Computed, Link } from "./types.js";
3
3
  export declare function addPendingSource(el: Computed<any>, source: Computed<any>): boolean;
4
4
  export declare function setPendingError(el: Computed<any>, source?: Computed<any>, error?: any): void;
5
5
  export declare function forEachDependent(el: Computed<any>, fn: (node: Computed<any>, link: Link) => void): void;
6
+ export declare function releaseSettledDependents(el: Computed<any>): void;
6
7
  export declare function settlePendingSource(el: Computed<any>): void;
7
8
  export declare function isThenable<T>(value: T | PromiseLike<T>): value is PromiseLike<T>;
8
9
  export declare function handleAsync<T>(el: Computed<T>, result: T | PromiseLike<T> | AsyncIterable<T>, setter?: (value: T) => void): T;
@@ -72,6 +72,21 @@ export declare function untrack<T>(fn: () => T, strictReadLabel?: string | false
72
72
  * date so its status flags reflect the current graph.
73
73
  */
74
74
  export declare function prepareComputed(comp: Computed<unknown>, refresh: boolean): void;
75
+ /**
76
+ * Sentinel returned by readNodeFast when the plain-signal fast path does not
77
+ * apply and the caller must fall back to the full read().
78
+ */
79
+ export declare const READ_SLOW: unique symbol;
80
+ /**
81
+ * read()'s plain-signal fast path as a standalone entry for hot callers
82
+ * (store traps). Safe to substitute for read() only because the bail
83
+ * conditions mirror read()'s prelude and fast-path guard exactly: the
84
+ * latestRead and pendingCheck windows run side-effectful hooks before the
85
+ * fast path, `_fn` nodes need prepareComputed, and firewall / override /
86
+ * snapshot / transition / lane / dev-strictRead state all take the full
87
+ * resolution. Anything slow returns READ_SLOW; the caller then calls read().
88
+ */
89
+ export declare function readNodeFast<T>(el: Signal<T>): T | typeof READ_SLOW;
75
90
  export declare function read<T>(el: Signal<T> | Computed<T>): T;
76
91
  export declare function setSignal<T>(el: Signal<T> | Computed<T>, v: T | ((prev: T) => T)): T;
77
92
  /**
@@ -41,5 +41,5 @@ import { type NoFn, type ProjectionOptions, type Store, type StoreSetter } from
41
41
  *
42
42
  * @returns `[store: Store<T>, setStore: StoreSetter<T>]`
43
43
  */
44
- export declare function createOptimisticStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T>>): [get: Store<T>, set: StoreSetter<T>];
44
+ export declare function createOptimisticStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T>>, options?: ProjectionOptions): [get: Store<T>, set: StoreSetter<T>];
45
45
  export declare function createOptimisticStore<T extends object = {}>(fn: (store: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, store: Partial<T> | Store<NoFn<T>>, options?: ProjectionOptions): [get: Refreshable<Store<T>>, set: StoreSetter<T>];
@@ -31,6 +31,8 @@ export interface StoreOptions {
31
31
  export interface ProjectionOptions extends StoreOptions {
32
32
  /** Key property name or function for reconciliation identity */
33
33
  key?: string | ((item: NonNullable<any>) => any);
34
+ /** Single-layer store: root keys reactive, values raw records replaced by reference */
35
+ shallow?: boolean;
34
36
  }
35
37
  export type NoFn<T> = T extends Function ? never : T;
36
38
  type DataNode = Signal<any>;
@@ -42,7 +44,7 @@ type DataNodes = Record<PropertyKey, DataNode>;
42
44
  * @internal
43
45
  */
44
46
  export declare const $TRACK: unique symbol, $TARGET: unique symbol, $PROXY: unique symbol, $DELETED: unique symbol, $AFFECTS: unique symbol;
45
- export declare const STORE_VALUE = "v", STORE_OVERRIDE = "o", STORE_OPTIMISTIC_OVERRIDE = "x", STORE_NODE = "n", STORE_HAS = "h", STORE_CUSTOM_PROTO = "c", STORE_WRAP = "w", STORE_LOOKUP = "l", STORE_FIREWALL = "f", STORE_OPTIMISTIC = "p", STORE_OPTIMISTIC_OWNERS = "t", STORE_PARENT = "u", STORE_DESC = "d";
47
+ export declare const STORE_VALUE = "v", STORE_OVERRIDE = "o", STORE_OPTIMISTIC_OVERRIDE = "x", STORE_NODE = "n", STORE_HAS = "h", STORE_CUSTOM_PROTO = "c", STORE_WRAP = "w", STORE_LOOKUP = "l", STORE_FIREWALL = "f", STORE_OPTIMISTIC = "p", STORE_OPTIMISTIC_OWNERS = "t", STORE_PARENT = "u", STORE_DESC = "d", STORE_SHALLOW = "s";
46
48
  export type StoreNode = {
47
49
  [$PROXY]: any;
48
50
  [STORE_VALUE]: Record<PropertyKey, any>;
@@ -58,6 +60,7 @@ export type StoreNode = {
58
60
  [STORE_OPTIMISTIC]?: boolean;
59
61
  [STORE_SNAPSHOT_PROPS]?: Record<PropertyKey, any>;
60
62
  [STORE_PARENT]?: StoreNode;
63
+ [STORE_SHALLOW]?: boolean;
61
64
  [STORE_DESC]?: boolean;
62
65
  };
63
66
  export declare namespace SolidStore {
@@ -68,7 +71,20 @@ export type NotWrappable = string | number | bigint | symbol | boolean | Functio
68
71
  export declare function createStoreProxy<T extends object>(value: T, traps?: ProxyHandler<StoreNode>, extend?: (target: StoreNode) => void): any;
69
72
  export declare const storeLookup: WeakMap<WeakKey, any>;
70
73
  export declare const symbolKeyedRecords: WeakSet<object>;
74
+ export declare function lookupTarget(value: any, lookup?: WeakMap<any, any>): StoreNode | undefined;
75
+ /**
76
+ * Marks a value as raw: no store will ever wrap it — every store presents it
77
+ * as-is, tracked by reference at whatever slot holds it and updated by
78
+ * replacement. Useful for class instances and external objects (editors,
79
+ * scene graphs, Maps) and for record-shaped data updated wholesale. Sticky
80
+ * for the value's lifetime.
81
+ */
82
+ export declare let rawValuesUsed: boolean;
83
+ export declare function isRawValue(value: any): boolean;
84
+ export declare function markRaw<T>(value: T): T;
85
+ export declare function markRawIngest(container: any): void;
71
86
  export declare function wrap<T extends Record<PropertyKey, any>>(value: T, target?: StoreNode): T;
87
+ export declare function wrapShallow<T extends Record<PropertyKey, any>>(value: T): T;
72
88
  export declare function isWrappable<T>(obj: T | NotWrappable): obj is T;
73
89
  export declare function setWriteOverride(value: boolean): void;
74
90
  export declare function ownEnumerableKeys(o: object): (string | symbol)[];
@@ -176,6 +192,8 @@ export declare function storeSetter<T extends object>(store: Store<T>, fn: (draf
176
192
  *
177
193
  * @returns `[store: Store<T>, setStore: StoreSetter<T>]`
178
194
  */
179
- export declare function createStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T>>): StoreReturn<T>;
195
+ export declare function createStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T>>, options?: StoreOptions & {
196
+ shallow?: boolean;
197
+ }): StoreReturn<T>;
180
198
  export declare function createStore<T extends object = {}>(fn: (store: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, store: Partial<T> | Store<NoFn<T>>, options?: ProjectionOptions): ProjectionStoreReturn<T>;
181
199
  export {};
@@ -3,6 +3,7 @@ import type { Computed, Link } from "./types.cjs";
3
3
  export declare function addPendingSource(el: Computed<any>, source: Computed<any>): boolean;
4
4
  export declare function setPendingError(el: Computed<any>, source?: Computed<any>, error?: any): void;
5
5
  export declare function forEachDependent(el: Computed<any>, fn: (node: Computed<any>, link: Link) => void): void;
6
+ export declare function releaseSettledDependents(el: Computed<any>): void;
6
7
  export declare function settlePendingSource(el: Computed<any>): void;
7
8
  export declare function isThenable<T>(value: T | PromiseLike<T>): value is PromiseLike<T>;
8
9
  export declare function handleAsync<T>(el: Computed<T>, result: T | PromiseLike<T> | AsyncIterable<T>, setter?: (value: T) => void): T;
@@ -72,6 +72,21 @@ export declare function untrack<T>(fn: () => T, strictReadLabel?: string | false
72
72
  * date so its status flags reflect the current graph.
73
73
  */
74
74
  export declare function prepareComputed(comp: Computed<unknown>, refresh: boolean): void;
75
+ /**
76
+ * Sentinel returned by readNodeFast when the plain-signal fast path does not
77
+ * apply and the caller must fall back to the full read().
78
+ */
79
+ export declare const READ_SLOW: unique symbol;
80
+ /**
81
+ * read()'s plain-signal fast path as a standalone entry for hot callers
82
+ * (store traps). Safe to substitute for read() only because the bail
83
+ * conditions mirror read()'s prelude and fast-path guard exactly: the
84
+ * latestRead and pendingCheck windows run side-effectful hooks before the
85
+ * fast path, `_fn` nodes need prepareComputed, and firewall / override /
86
+ * snapshot / transition / lane / dev-strictRead state all take the full
87
+ * resolution. Anything slow returns READ_SLOW; the caller then calls read().
88
+ */
89
+ export declare function readNodeFast<T>(el: Signal<T>): T | typeof READ_SLOW;
75
90
  export declare function read<T>(el: Signal<T> | Computed<T>): T;
76
91
  export declare function setSignal<T>(el: Signal<T> | Computed<T>, v: T | ((prev: T) => T)): T;
77
92
  /**
@@ -41,5 +41,5 @@ import { type NoFn, type ProjectionOptions, type Store, type StoreSetter } from
41
41
  *
42
42
  * @returns `[store: Store<T>, setStore: StoreSetter<T>]`
43
43
  */
44
- export declare function createOptimisticStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T>>): [get: Store<T>, set: StoreSetter<T>];
44
+ export declare function createOptimisticStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T>>, options?: ProjectionOptions): [get: Store<T>, set: StoreSetter<T>];
45
45
  export declare function createOptimisticStore<T extends object = {}>(fn: (store: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, store: Partial<T> | Store<NoFn<T>>, options?: ProjectionOptions): [get: Refreshable<Store<T>>, set: StoreSetter<T>];
@@ -31,6 +31,8 @@ export interface StoreOptions {
31
31
  export interface ProjectionOptions extends StoreOptions {
32
32
  /** Key property name or function for reconciliation identity */
33
33
  key?: string | ((item: NonNullable<any>) => any);
34
+ /** Single-layer store: root keys reactive, values raw records replaced by reference */
35
+ shallow?: boolean;
34
36
  }
35
37
  export type NoFn<T> = T extends Function ? never : T;
36
38
  type DataNode = Signal<any>;
@@ -42,7 +44,7 @@ type DataNodes = Record<PropertyKey, DataNode>;
42
44
  * @internal
43
45
  */
44
46
  export declare const $TRACK: unique symbol, $TARGET: unique symbol, $PROXY: unique symbol, $DELETED: unique symbol, $AFFECTS: unique symbol;
45
- export declare const STORE_VALUE = "v", STORE_OVERRIDE = "o", STORE_OPTIMISTIC_OVERRIDE = "x", STORE_NODE = "n", STORE_HAS = "h", STORE_CUSTOM_PROTO = "c", STORE_WRAP = "w", STORE_LOOKUP = "l", STORE_FIREWALL = "f", STORE_OPTIMISTIC = "p", STORE_OPTIMISTIC_OWNERS = "t", STORE_PARENT = "u", STORE_DESC = "d";
47
+ export declare const STORE_VALUE = "v", STORE_OVERRIDE = "o", STORE_OPTIMISTIC_OVERRIDE = "x", STORE_NODE = "n", STORE_HAS = "h", STORE_CUSTOM_PROTO = "c", STORE_WRAP = "w", STORE_LOOKUP = "l", STORE_FIREWALL = "f", STORE_OPTIMISTIC = "p", STORE_OPTIMISTIC_OWNERS = "t", STORE_PARENT = "u", STORE_DESC = "d", STORE_SHALLOW = "s";
46
48
  export type StoreNode = {
47
49
  [$PROXY]: any;
48
50
  [STORE_VALUE]: Record<PropertyKey, any>;
@@ -58,6 +60,7 @@ export type StoreNode = {
58
60
  [STORE_OPTIMISTIC]?: boolean;
59
61
  [STORE_SNAPSHOT_PROPS]?: Record<PropertyKey, any>;
60
62
  [STORE_PARENT]?: StoreNode;
63
+ [STORE_SHALLOW]?: boolean;
61
64
  [STORE_DESC]?: boolean;
62
65
  };
63
66
  export declare namespace SolidStore {
@@ -68,7 +71,20 @@ export type NotWrappable = string | number | bigint | symbol | boolean | Functio
68
71
  export declare function createStoreProxy<T extends object>(value: T, traps?: ProxyHandler<StoreNode>, extend?: (target: StoreNode) => void): any;
69
72
  export declare const storeLookup: WeakMap<WeakKey, any>;
70
73
  export declare const symbolKeyedRecords: WeakSet<object>;
74
+ export declare function lookupTarget(value: any, lookup?: WeakMap<any, any>): StoreNode | undefined;
75
+ /**
76
+ * Marks a value as raw: no store will ever wrap it — every store presents it
77
+ * as-is, tracked by reference at whatever slot holds it and updated by
78
+ * replacement. Useful for class instances and external objects (editors,
79
+ * scene graphs, Maps) and for record-shaped data updated wholesale. Sticky
80
+ * for the value's lifetime.
81
+ */
82
+ export declare let rawValuesUsed: boolean;
83
+ export declare function isRawValue(value: any): boolean;
84
+ export declare function markRaw<T>(value: T): T;
85
+ export declare function markRawIngest(container: any): void;
71
86
  export declare function wrap<T extends Record<PropertyKey, any>>(value: T, target?: StoreNode): T;
87
+ export declare function wrapShallow<T extends Record<PropertyKey, any>>(value: T): T;
72
88
  export declare function isWrappable<T>(obj: T | NotWrappable): obj is T;
73
89
  export declare function setWriteOverride(value: boolean): void;
74
90
  export declare function ownEnumerableKeys(o: object): (string | symbol)[];
@@ -176,6 +192,8 @@ export declare function storeSetter<T extends object>(store: Store<T>, fn: (draf
176
192
  *
177
193
  * @returns `[store: Store<T>, setStore: StoreSetter<T>]`
178
194
  */
179
- export declare function createStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T>>): StoreReturn<T>;
195
+ export declare function createStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T>>, options?: StoreOptions & {
196
+ shallow?: boolean;
197
+ }): StoreReturn<T>;
180
198
  export declare function createStore<T extends object = {}>(fn: (store: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, store: Partial<T> | Store<NoFn<T>>, options?: ProjectionOptions): ProjectionStoreReturn<T>;
181
199
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidjs/signals",
3
- "version": "2.0.0-beta.24",
3
+ "version": "2.0.0-beta.26",
4
4
  "description": "Solid's reactive primitives: signals, memos, effects, stores, and async-aware computations.",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",