@solidjs/signals 2.0.0-beta.7 → 2.0.0-beta.9

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 (40) hide show
  1. package/dist/dev.js +401 -199
  2. package/dist/node.cjs +1403 -1259
  3. package/dist/prod.js +1053 -905
  4. package/dist/types/boundaries.d.ts +79 -3
  5. package/dist/types/core/action.d.ts +34 -0
  6. package/dist/types/core/constants.d.ts +17 -0
  7. package/dist/types/core/core.d.ts +108 -9
  8. package/dist/types/core/dev.d.ts +1 -1
  9. package/dist/types/core/effect.d.ts +3 -2
  10. package/dist/types/core/owner.d.ts +54 -3
  11. package/dist/types/core/scheduler.d.ts +19 -2
  12. package/dist/types/core/types.d.ts +2 -5
  13. package/dist/types/index.d.ts +2 -2
  14. package/dist/types/map.d.ts +32 -3
  15. package/dist/types/signals.d.ts +283 -16
  16. package/dist/types/store/optimistic.d.ts +38 -12
  17. package/dist/types/store/projection.d.ts +54 -14
  18. package/dist/types/store/reconcile.d.ts +22 -0
  19. package/dist/types/store/store.d.ts +64 -14
  20. package/dist/types/store/storePath.d.ts +28 -0
  21. package/dist/types/store/utils.d.ts +78 -7
  22. package/dist/types-cjs/boundaries.d.cts +79 -3
  23. package/dist/types-cjs/core/action.d.cts +34 -0
  24. package/dist/types-cjs/core/constants.d.cts +17 -0
  25. package/dist/types-cjs/core/core.d.cts +108 -9
  26. package/dist/types-cjs/core/dev.d.cts +1 -1
  27. package/dist/types-cjs/core/effect.d.cts +3 -2
  28. package/dist/types-cjs/core/owner.d.cts +54 -3
  29. package/dist/types-cjs/core/scheduler.d.cts +19 -2
  30. package/dist/types-cjs/core/types.d.cts +2 -5
  31. package/dist/types-cjs/index.d.cts +2 -2
  32. package/dist/types-cjs/map.d.cts +32 -3
  33. package/dist/types-cjs/signals.d.cts +283 -16
  34. package/dist/types-cjs/store/optimistic.d.cts +38 -12
  35. package/dist/types-cjs/store/projection.d.cts +54 -14
  36. package/dist/types-cjs/store/reconcile.d.cts +22 -0
  37. package/dist/types-cjs/store/store.d.cts +64 -14
  38. package/dist/types-cjs/store/storePath.d.cts +28 -0
  39. package/dist/types-cjs/store/utils.d.cts +78 -7
  40. package/package.json +4 -3
@@ -1,5 +1,21 @@
1
- import { $REFRESH, STORE_SNAPSHOT_PROPS, type Computed, type Signal } from "../core/index.cjs";
1
+ import { STORE_SNAPSHOT_PROPS, type Computed, type Refreshable, type Signal } from "../core/index.cjs";
2
+ /** A read-only view of a store's value as seen by consumers. Mutate it via the paired `StoreSetter`. */
2
3
  export type Store<T> = Readonly<T>;
4
+ /**
5
+ * A store setter. The callback receives a writable **draft** of the store.
6
+ *
7
+ * - **Mutate in place (canonical):** `s.foo = 1`, `s.list.push(x)`,
8
+ * `s.list.splice(i, 1)`. This is the default form for most updates.
9
+ * - **Return a new value:** for shapes where mutation is awkward, most
10
+ * commonly removing items (`s => s.list.filter(...)`). Arrays are replaced
11
+ * by index (length adjusted); objects are shallow-diffed at the top level
12
+ * (keys present in the returned value are written, missing keys deleted).
13
+ *
14
+ * The setter does **not** perform keyed reconciliation. If you need surviving
15
+ * items to keep their store identity across full-array replacement, use the
16
+ * projection form — `createStore(fn, seed, { key })` or `createProjection` —
17
+ * whose derive function reconciles its return by `options.key`.
18
+ */
3
19
  export type StoreSetter<T> = (fn: (state: T) => T | void) => void;
4
20
  /** Base options for store primitives. */
5
21
  export interface StoreOptions {
@@ -45,24 +61,58 @@ export declare function getPropertyDescriptor(source: Record<PropertyKey, any>,
45
61
  export declare const storeTraps: ProxyHandler<StoreNode>;
46
62
  export declare function storeSetter<T extends object>(store: Store<T>, fn: (draft: T) => T | void): void;
47
63
  /**
48
- * Creates a deeply reactive store with proxy-based tracking.
64
+ * Creates a deeply-reactive store backed by a Proxy. Reads track each property
65
+ * accessed; only the parts that change trigger updates.
66
+ *
67
+ * Store properties hold **plain values**, not accessors. The proxy already
68
+ * tracks reads per-property — wrapping a value in `() => state.foo` produces
69
+ * a getter that *won't* track when called, which looks like a reactivity bug
70
+ * but is just a category error. If you have a signal-shaped piece of state,
71
+ * make it a property of the store (`{ foo: 1 }`) rather than nesting an
72
+ * accessor inside (`{ foo: () => signal() }`).
49
73
  *
50
- * When called with a plain value, wraps it in a reactive proxy.
51
- * When called with a function, creates a derived projection store with `ProjectionOptions` (name, key, all).
74
+ * The setter takes a **draft-mutating** function mutate the draft in place
75
+ * (canonical). The callback may also return a new value: arrays are replaced
76
+ * by index (length adjusted), objects are shallow-diffed at the top level
77
+ * (keys present in the returned value are written, missing keys deleted). Use
78
+ * the return form for shapes where mutation is awkward — most commonly
79
+ * removing items via `filter`. The setter does **not** do keyed reconciliation;
80
+ * for that, use the derived/projection form (or `createProjection`).
81
+ *
82
+ * - Plain form: `createStore(initialValue)` — wraps a value in a reactive
83
+ * proxy.
84
+ * - Derived form: `createStore(fn, seed, options?)` — a *projection store*
85
+ * whose contents are computed by `fn(draft)`. `fn` may be sync, async, or
86
+ * an `AsyncIterable`; the projection's result reconciles against the
87
+ * existing store by `options.key` (default `"id"`) for stable identity.
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * const [state, setState] = createStore({
92
+ * user: { name: "Ada", age: 36 },
93
+ * todos: [] as { id: string; text: string; done: boolean }[]
94
+ * });
95
+ *
96
+ * // Canonical: mutate the draft in place.
97
+ * setState(s => { s.user.age = 37; });
98
+ * setState(s => { s.todos.push({ id: "1", text: "x", done: false }); });
99
+ *
100
+ * // Return form: reach for it when mutation is awkward.
101
+ * setState(s => s.todos.filter(t => !t.done)); // remove items
102
+ * setState(s => ({ ...s, user: { name: "Grace", age: 85 } })); // shallow replace
103
+ * ```
52
104
  *
53
- * ```typescript
54
- * // Plain store
55
- * const [store, setStore] = createStore<T>(initialValue);
56
- * // Derived store (projection)
57
- * const [store, setStore] = createStore<T>(fn, seed, options?: ProjectionOptions);
105
+ * @example
106
+ * ```ts
107
+ * // Derived store auto-fetches & reconciles by `id`.
108
+ * const [users] = createStore(
109
+ * async () => fetch("/users").then(r => r.json()),
110
+ * [] as User[]
111
+ * );
58
112
  * ```
59
- * @param store initial value to wrap in a reactive proxy, or a derive function
60
- * @param options `ProjectionOptions` -- name, key, all (only for derived stores)
61
113
  *
62
114
  * @returns `[store: Store<T>, setStore: StoreSetter<T>]`
63
115
  */
64
116
  export declare function createStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T>>): [get: Store<T>, set: StoreSetter<T>];
65
- 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): [get: Store<T> & {
66
- [$REFRESH]: any;
67
- }, set: StoreSetter<T>];
117
+ 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): [get: Refreshable<Store<T>>, set: StoreSetter<T>];
68
118
  export {};
@@ -26,5 +26,33 @@ export interface storePath {
26
26
  <T, K1 extends KeyOf<W<T>>>(k1: Part<W<T>, K1>, setter: PathSetter<W<T>[K1]>): (state: T) => void;
27
27
  <T>(setter: PathSetter<T>): (state: T) => void;
28
28
  }
29
+ /**
30
+ * Path-based setter helper for `createStore`. Call `storePath(...path, value)`
31
+ * to produce a draft-mutating function suitable for passing to `setStore`.
32
+ *
33
+ * The canonical setter form in Solid 2.0 is the draft-mutating callback
34
+ * (`setStore(s => { s.user.name = "Ada"; })`). `storePath` is a backwards-
35
+ * compatibility helper for users porting from Solid 1.x's
36
+ * `setStore("user", "name", "Ada")` style — it's optional and you can mix the
37
+ * two styles freely.
38
+ *
39
+ * Path parts can be:
40
+ * - a single key — `"user"`, `0`
41
+ * - an array of keys — `[0, 1, 2]`
42
+ * - a range over an array — `{ from?, to?, by? }`
43
+ * - a filter `(item, index) => boolean` for arrays
44
+ *
45
+ * The final argument is the new value or an updater `(prev) => next`. Use
46
+ * `storePath.DELETE` to remove a property.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * const [state, setState] = createStore({ user: { name: "Ada" }, todos: [] });
51
+ *
52
+ * setState(storePath("user", "name", "Grace"));
53
+ * setState(storePath("todos", t => !t.done, "done", true)); // mark all undone as done
54
+ * setState(storePath("user", "nickname", storePath.DELETE));
55
+ * ```
56
+ */
29
57
  export declare const storePath: storePath;
30
58
  export {};
@@ -1,15 +1,41 @@
1
1
  /**
2
- * Returns a non reactive copy of the store object.
3
- * It will attempt to preserver the original reference unless the value has been modified.
4
- * @param item store proxy object
2
+ * Returns a plain (non-proxy, non-reactive) deep copy of a store value.
3
+ * Reading via `snapshot` does **not** subscribe to changes use this when you
4
+ * need to hand a stable plain object to non-reactive code (logging,
5
+ * serialization, structured-clone, network payloads, etc.).
6
+ *
7
+ * Returns the original object identity for any sub-tree that wasn't modified
8
+ * relative to the proxy's underlying source.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const [state] = createStore({ user: { name: "Ada" }, todos: [] });
13
+ *
14
+ * console.log(JSON.stringify(snapshot(state))); // safe, non-reactive copy
15
+ * ```
5
16
  */
6
17
  export declare function snapshot<T>(item: T): T;
7
18
  export declare function snapshot<T>(item: T, map?: Map<unknown, unknown>, lookup?: WeakMap<any, any>): T;
8
19
  /**
9
- * Returns a non-reactive snapshot of the store while subscribing to all nested changes.
10
- * Subscribes to `$TRACK` at every level so that any deep change triggers recomputation,
11
- * and returns plain (non-proxy) data. Works correctly with `reconcile()`.
12
- * @param store store proxy object
20
+ * Returns a plain (non-proxy) deep copy **and** subscribes the current
21
+ * tracking scope to every nested change in the source store. Any write
22
+ * anywhere in the subtree invalidates the consumer.
23
+ *
24
+ * Use this when you need plain data inside a reactive scope and want to
25
+ * react to deep mutations (e.g. passing a snapshot to `reconcile()` or to a
26
+ * memo that should rerun on any nested change). For most read paths, prefer
27
+ * direct property access — Solid stores already track per-property reads
28
+ * with no `deep()` wrapper needed.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * const [state] = createStore({ a: { b: { c: 1 } } });
33
+ *
34
+ * createEffect(
35
+ * () => deep(state), // reruns on any nested change
36
+ * plain => sendToWorker(plain) // worker gets a non-proxy copy
37
+ * );
38
+ * ```
13
39
  */
14
40
  export declare function deep<T extends object>(store: T): T;
15
41
  type DistributeOverride<T, F> = T extends undefined ? F : T;
@@ -35,9 +61,54 @@ type _Merge<T extends unknown[], Curr = {}> = T extends [
35
61
  ...infer Rest
36
62
  ] ? _Merge<Rest, Override<Curr, Next>> : T extends [...infer Rest, infer Next | (() => infer Next)] ? Override<_Merge<Rest, Curr>, Next> : T extends [] ? Curr : T extends (infer I | (() => infer I))[] ? OverrideSpread<Curr, I> : Curr;
37
63
  export type Merge<T extends unknown[]> = Simplify<_Merge<T>>;
64
+ /**
65
+ * Merges multiple props-like objects into a single proxy that *preserves
66
+ * reactivity*. Reads are forwarded to the right-most source that defines the
67
+ * property, so later sources override earlier ones (like `Object.assign`).
68
+ *
69
+ * Function arguments are treated as memo-backed sources — useful for passing
70
+ * derived defaults whose computation should track reactively.
71
+ *
72
+ * Use this in component bodies to merge defaults / overrides without losing
73
+ * Solid's per-property tracking.
74
+ *
75
+ * @example
76
+ * ```tsx
77
+ * function Button(_props: { label: string; type?: string; disabled?: boolean }) {
78
+ * const props = merge({ type: "button", disabled: false }, _props);
79
+ *
80
+ * return <button type={props.type} disabled={props.disabled}>{props.label}</button>;
81
+ * }
82
+ * ```
83
+ */
38
84
  export declare function merge<T extends unknown[]>(...sources: T): Merge<T>;
39
85
  export type Omit<T, K extends readonly (keyof T)[]> = {
40
86
  [P in keyof T as Exclude<P, K[number]>]: T[P];
41
87
  };
88
+ /**
89
+ * Returns a reactive proxy of `props` with the listed keys hidden. Tracking
90
+ * on the remaining keys is preserved.
91
+ *
92
+ * Use it to forward "rest" props to a child element while pulling out the
93
+ * keys your component handles itself — the equivalent of `splitProps(p, ["a","b"])[1]`.
94
+ *
95
+ * @example
96
+ * ```tsx
97
+ * function Input(props: { label: string; value: string; onInput: (v: string) => void } & JSX.HTMLAttributes<HTMLInputElement>) {
98
+ * const rest = omit(props, "label", "value", "onInput");
99
+ *
100
+ * return (
101
+ * <label>
102
+ * {props.label}
103
+ * <input
104
+ * {...rest}
105
+ * value={props.value}
106
+ * onInput={e => props.onInput(e.currentTarget.value)}
107
+ * />
108
+ * </label>
109
+ * );
110
+ * }
111
+ * ```
112
+ */
42
113
  export declare function omit<T extends Record<any, any>, K extends readonly (keyof T)[]>(props: T, ...keys: K): Omit<T, K>;
43
114
  export {};
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@solidjs/signals",
3
- "version": "2.0.0-beta.7",
4
- "description": "SolidJS' reactive core implementation",
3
+ "version": "2.0.0-beta.9",
4
+ "description": "Solid's reactive primitives: signals, memos, effects, stores, and async-aware computations.",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "homepage": "https://solidjs.com",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "https://github.com/solidjs/solid"
10
+ "url": "git+https://github.com/solidjs/solid.git",
11
+ "directory": "packages/solid-signals"
11
12
  },
12
13
  "publishConfig": {
13
14
  "access": "public"