Skip to content

Commit 5c3d473

Browse files
committed
Refine Solid v2 reference generation
1 parent f93a008 commit 5c3d473

73 files changed

Lines changed: 1449 additions & 72 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

scripts/extract-solid-ref.mjs

Lines changed: 223 additions & 54 deletions
Large diffs are not rendered by default.

src/routes/v2/reference/reactivity/create-effect.mdx renamed to src/routes/v2/reference/(1)reactivity/create-effect.mdx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,52 @@ createEffect(
9797
}
9898
);
9999
```
100+
101+
## Related types
102+
103+
### `ComputeFunction`
104+
105+
```ts
106+
type ComputeFunction<Prev, Next extends Prev = Prev> = (
107+
v: Prev
108+
) => PromiseLike<Next> | AsyncIterable<Next> | Next;
109+
```
110+
111+
### `EffectBundle`
112+
113+
```ts
114+
type EffectBundle<Prev, Next extends Prev = Prev> = {
115+
effect: EffectFunction<Prev, Next>;
116+
error: (err: unknown, cleanup: () => void) => void;
117+
};
118+
```
119+
120+
### `EffectFunction`
121+
122+
```ts
123+
type EffectFunction<Prev, Next extends Prev = Prev> = (
124+
v: Next,
125+
p?: Prev
126+
) => (() => void) | void;
127+
```
128+
129+
### `EffectOptions`
130+
131+
Options for effect primitives that support deferring/scheduling their initial run (`createEffect`, `createRenderEffect`, `createReaction`).
132+
133+
```ts
134+
interface EffectOptions extends BaseEffectOptions {
135+
/** When true, defers the initial effect execution until the next change */
136+
defer?: boolean;
137+
/**
138+
* When true, enqueues the initial effect callback through the effect queue instead of running
139+
* it synchronously at creation. Lets the initial run participate in transitions -- if any
140+
* source throws `NotReadyError` during the compute phase, the callback is held until the
141+
* transition settles.
142+
*
143+
* Primarily for render effects that need transition-aware initial mounts (e.g. the root
144+
* `insert()` in `render()`).
145+
*/
146+
schedule?: boolean;
147+
};
148+
```
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
title: "createMemo"
3+
category: "Reactivity"
4+
version: "2.0"
5+
description: "Creates a readonly derived reactive memoized signal."
6+
source_repo: "solidjs/solid"
7+
source_ref: "next"
8+
source_sha: "a93a216ef35bd053949493506942884fb24e7684"
9+
source_path: "packages/solid-signals/src/signals.ts"
10+
---
11+
12+
{/* Generated by scripts/extract-solid-ref.mjs. Edit the source JSDoc or disposition map, then regenerate. */}
13+
14+
Creates a readonly derived reactive memoized signal.
15+
16+
```typescript
17+
const value = createMemo<T>(compute, options?: MemoOptions<T>);
18+
```
19+
20+
## Import
21+
22+
```ts
23+
import { createMemo } from "solid-js";
24+
```
25+
26+
## Type signature
27+
28+
```ts
29+
function createMemo<T>(
30+
compute: ComputeFunction<undefined | NoInfer<T>, T>,
31+
options?: MemoOptions<T>
32+
): Accessor<T>;
33+
```
34+
35+
## Parameters
36+
37+
### `compute`
38+
39+
a function that receives its previous value and returns a new value used to react on a computation
40+
41+
### `options`
42+
43+
`MemoOptions` -- id, name, equals, unobserved, lazy
44+
45+
## Examples
46+
47+
```ts
48+
const [first, setFirst] = createSignal("Ada");
49+
const [last, setLast] = createSignal("Lovelace");
50+
51+
const fullName = createMemo(() => `${first()} ${last()}`);
52+
53+
fullName(); // "Ada Lovelace"
54+
```
55+
56+
```ts
57+
// Async memo — reads surface as pending inside <Loading>
58+
const user = createMemo(async () => {
59+
const res = await fetch(`/users/${id()}`);
60+
return res.json();
61+
});
62+
```
63+
64+
## Related types
65+
66+
### `isEqual`
67+
68+
```ts
69+
function isEqual<T>(a: T, b: T): boolean;
70+
```
71+
72+
### `MemoOptions`
73+
74+
Options for read-only memos created with `createMemo`.
75+
Also used in combination with `SignalOptions` for writable memos
76+
(`createSignal(fn)` / `createOptimistic(fn)`).
77+
78+
```ts
79+
interface MemoOptions<T> {
80+
/** Stable identifier for the owner hierarchy */
81+
id?: string;
82+
/** Debug name (dev mode only) */
83+
name?: string;
84+
/** When true, the owner is invisible to the ID scheme -- inherits parent ID and doesn't consume a childCount slot */
85+
transparent?: boolean;
86+
/**
87+
* Custom equality function, or `false` to always notify subscribers.
88+
* Defaults to reference equality (`isEqual`). Pass a comparator (e.g.
89+
* `(a, b) => a.id === b.id`) for value-based equality, or `false` to
90+
* notify on every recompute regardless of equality.
91+
*/
92+
equals?: false | ((prev: T, next: T) => boolean);
93+
/** Callback invoked when the computed loses all subscribers */
94+
unobserved?: () => void;
95+
/**
96+
* When true, defers the initial computation until the value is first read,
97+
* **and** opts the memo into autodisposal — once it has no remaining
98+
* subscribers it is torn down and recomputed from scratch on the next read.
99+
* Use it for compute-on-demand values that should not retain state across
100+
* idle periods. Non-lazy owned memos live for their owner's lifetime and
101+
* never autodispose.
102+
*/
103+
lazy?: boolean;
104+
};
105+
```
106+
107+
### `SignalOptions`
108+
109+
Options for plain signals created with `createSignal(value)` or `createOptimistic(value)`.
110+
111+
```ts
112+
interface SignalOptions<T> {
113+
/** Debug name (dev mode only) */
114+
name?: string;
115+
/**
116+
* Custom equality function, or `false` to always notify subscribers.
117+
* Defaults to reference equality (`isEqual`). Pass a comparator (e.g.
118+
* `(a, b) => a.id === b.id`) for value-based equality, or `false` to
119+
* notify on every write regardless of equality.
120+
*/
121+
equals?: false | ((prev: T, next: T) => boolean);
122+
/** Suppress dev-mode warnings when writing inside an owned scope */
123+
ownedWrite?: boolean;
124+
/** Callback invoked when the signal loses all subscribers */
125+
unobserved?: () => void;
126+
};
127+
```

src/routes/v2/reference/reactivity/create-optimistic.mdx renamed to src/routes/v2/reference/(1)reactivity/create-optimistic.mdx

File renamed without changes.
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
---
2+
title: "createSignal"
3+
category: "Reactivity"
4+
version: "2.0"
5+
description: "Creates a simple reactive state with a getter and setter."
6+
source_repo: "solidjs/solid"
7+
source_ref: "next"
8+
source_sha: "a93a216ef35bd053949493506942884fb24e7684"
9+
source_path: "packages/solid-signals/src/signals.ts"
10+
---
11+
12+
{/* Generated by scripts/extract-solid-ref.mjs. Edit the source JSDoc or disposition map, then regenerate. */}
13+
14+
Creates a simple reactive state with a getter and setter.
15+
16+
When called with a plain value, creates a signal with `SignalOptions` (name, equals, ownedWrite, unobserved).
17+
When called with a function, creates a writable memo with `SignalOptions & MemoOptions` (adds id, lazy).
18+
19+
```typescript
20+
// Plain signal
21+
const [state, setState] = createSignal<T>(value, options?: SignalOptions<T>);
22+
// Writable memo (function overload)
23+
const [state, setState] = createSignal<T>(fn, initialValue?, options?: SignalOptions<T> & MemoOptions<T>);
24+
```
25+
26+
## Import
27+
28+
```ts
29+
import { createSignal } from "solid-js";
30+
```
31+
32+
## Type signature
33+
34+
```ts
35+
function createSignal<T>(): Signal<T | undefined>;
36+
function createSignal<T>(value: Exclude<T, Function>, options?: SignalOptions<T>): Signal<T>;
37+
function createSignal<T>(
38+
fn: ComputeFunction<T>,
39+
options?: SignalOptions<T> & MemoOptions<T>
40+
): Signal<T>;
41+
```
42+
43+
## Parameters
44+
45+
### `value`
46+
47+
initial value of the state; if empty, the state's type will automatically extended with undefined
48+
49+
### `options`
50+
51+
optional object with a name for debugging purposes and equals, a comparator function for the previous and next value to allow fine-grained control over the reactivity
52+
53+
## Return value
54+
55+
`[state: Accessor<T>, setState: Setter<T>]`
56+
57+
## Examples
58+
59+
```ts
60+
const [count, setCount] = createSignal(0);
61+
62+
count(); // 0
63+
setCount(1); // explicit value
64+
setCount(c => c + 1); // updater
65+
```
66+
67+
```ts
68+
// Writable memo: starts as `fn()`, can be locally overwritten by setter.
69+
const [user, setUser] = createSignal(() => fetchUser(userId()));
70+
71+
setUser({ ...user(), name: "Alice" }); // optimistic local edit
72+
```
73+
74+
## Related types
75+
76+
### `isEqual`
77+
78+
```ts
79+
function isEqual<T>(a: T, b: T): boolean;
80+
```
81+
82+
### `MemoOptions`
83+
84+
Options for read-only memos created with `createMemo`.
85+
Also used in combination with `SignalOptions` for writable memos
86+
(`createSignal(fn)` / `createOptimistic(fn)`).
87+
88+
```ts
89+
interface MemoOptions<T> {
90+
/** Stable identifier for the owner hierarchy */
91+
id?: string;
92+
/** Debug name (dev mode only) */
93+
name?: string;
94+
/** When true, the owner is invisible to the ID scheme -- inherits parent ID and doesn't consume a childCount slot */
95+
transparent?: boolean;
96+
/**
97+
* Custom equality function, or `false` to always notify subscribers.
98+
* Defaults to reference equality (`isEqual`). Pass a comparator (e.g.
99+
* `(a, b) => a.id === b.id`) for value-based equality, or `false` to
100+
* notify on every recompute regardless of equality.
101+
*/
102+
equals?: false | ((prev: T, next: T) => boolean);
103+
/** Callback invoked when the computed loses all subscribers */
104+
unobserved?: () => void;
105+
/**
106+
* When true, defers the initial computation until the value is first read,
107+
* **and** opts the memo into autodisposal — once it has no remaining
108+
* subscribers it is torn down and recomputed from scratch on the next read.
109+
* Use it for compute-on-demand values that should not retain state across
110+
* idle periods. Non-lazy owned memos live for their owner's lifetime and
111+
* never autodispose.
112+
*/
113+
lazy?: boolean;
114+
};
115+
```
116+
117+
### `NoInfer`
118+
119+
```ts
120+
type NoInfer<T extends any> = [T][T extends any ? 0 : never];
121+
```
122+
123+
### `SignalOptions`
124+
125+
Options for plain signals created with `createSignal(value)` or `createOptimistic(value)`.
126+
127+
```ts
128+
interface SignalOptions<T> {
129+
/** Debug name (dev mode only) */
130+
name?: string;
131+
/**
132+
* Custom equality function, or `false` to always notify subscribers.
133+
* Defaults to reference equality (`isEqual`). Pass a comparator (e.g.
134+
* `(a, b) => a.id === b.id`) for value-based equality, or `false` to
135+
* notify on every write regardless of equality.
136+
*/
137+
equals?: false | ((prev: T, next: T) => boolean);
138+
/** Suppress dev-mode warnings when writing inside an owned scope */
139+
ownedWrite?: boolean;
140+
/** Callback invoked when the signal loses all subscribers */
141+
unobserved?: () => void;
142+
};
143+
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/routes/v2/reference/stores/create-optimistic-store.mdx renamed to src/routes/v2/reference/(2)stores/create-optimistic-store.mdx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,18 @@ const removeTodo = action(function* (id: string) {
7474
yield api.removeTodo(id);
7575
});
7676
```
77+
78+
## Related types
79+
80+
### `Refreshable`
81+
82+
Brand applied to derived/projected stores indicating they participate in
83+
the `refresh()` re-run protocol. Use this alias instead of inlining
84+
`T & { [$REFRESH]: any }` so that user-defined hooks that wrap
85+
`createOptimisticStore` / `createProjection` / projection-form
86+
`createStore` can have their return types inferred without leaking the
87+
internal `$REFRESH` symbol into public type signatures (TS4058).
88+
89+
```ts
90+
type Refreshable<T> = T & { readonly [$REFRESH]: any };
91+
```

0 commit comments

Comments
 (0)