solid-js 2.0.0-beta.8 → 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.
- package/CHEATSHEET.md +562 -0
- package/README.md +44 -188
- package/package.json +7 -5
- package/types/client/component.d.ts +50 -0
- package/types/client/core.d.ts +98 -21
- package/types/client/flow.d.ts +63 -11
- package/types/client/hydration.d.ts +380 -18
- package/types/index.d.ts +1 -1
- package/types/server/core.d.ts +14 -9
- package/types/server/index.d.ts +1 -1
- package/types/server/signals.d.ts +1 -1
- package/types-cjs/client/component.d.cts +50 -0
- package/types-cjs/client/core.d.cts +98 -21
- package/types-cjs/client/flow.d.cts +63 -11
- package/types-cjs/client/hydration.d.cts +380 -18
- package/types-cjs/index.d.cts +1 -1
- package/types-cjs/server/core.d.cts +14 -9
- package/types-cjs/server/index.d.cts +1 -1
- package/types-cjs/server/signals.d.cts +1 -1
|
@@ -9,34 +9,101 @@ export type ContextProviderComponent<T> = FlowComponent<{
|
|
|
9
9
|
}>;
|
|
10
10
|
export interface Context<T> extends ContextProviderComponent<T> {
|
|
11
11
|
id: symbol;
|
|
12
|
-
defaultValue: T;
|
|
12
|
+
defaultValue: T | undefined;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
* Creates a Context
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
15
|
+
* Creates a Context for sharing state with descendants of a Provider in the
|
|
16
|
+
* component tree.
|
|
17
|
+
*
|
|
18
|
+
* The returned `Context` is itself a provider component — pass it a `value`
|
|
19
|
+
* prop to scope a value to its children. Read it inside descendants with
|
|
20
|
+
* `useContext`.
|
|
21
|
+
*
|
|
22
|
+
* Two forms:
|
|
23
|
+
*
|
|
24
|
+
* - **`createContext<T>()`** (default-less, the canonical form). Reading via
|
|
25
|
+
* `useContext` outside an enclosing Provider throws `ContextNotFoundError`.
|
|
26
|
+
* Use this for everything that carries reactive state — signals, stores,
|
|
27
|
+
* `[state, actions]` tuples, services. The Provider is mandatory by
|
|
28
|
+
* construction; the throw makes a missing Provider a loud bug instead of a
|
|
29
|
+
* silent no-op. The annotation `<T>` is required because there is no value
|
|
30
|
+
* to infer from.
|
|
31
|
+
* - **`createContext<T>(defaultValue)`** (default form). Reserved for the
|
|
32
|
+
* narrow case of contexts whose value is a primitive with a meaningful
|
|
33
|
+
* static fallback (theme, locale, frozen config). Outside any Provider,
|
|
34
|
+
* `useContext` returns `defaultValue`.
|
|
35
|
+
*
|
|
36
|
+
* If you want truly app-wide state, **don't use Context** — a module-scope
|
|
37
|
+
* signal/store *is* a global. Context is for scoping state to a subtree;
|
|
38
|
+
* that's why a Provider is required.
|
|
39
|
+
*
|
|
40
|
+
* @param defaultValue optional default; only meaningful for primitive
|
|
41
|
+
* fallbacks. Omit for any context carrying reactive state.
|
|
42
|
+
* @param options `{ name }` for debugging in development
|
|
43
|
+
* @returns a context object that doubles as its own provider component
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```tsx
|
|
47
|
+
* // Reactive payload — default-less, throws if no Provider.
|
|
48
|
+
* type TodosCtx = readonly [Store<Todo[]>, TodoActions];
|
|
49
|
+
* const TodosContext = createContext<TodosCtx>();
|
|
50
|
+
*
|
|
51
|
+
* function App() {
|
|
52
|
+
* return (
|
|
53
|
+
* <TodosContext value={createTodos()}>
|
|
54
|
+
* <TodoList />
|
|
55
|
+
* </TodosContext>
|
|
56
|
+
* );
|
|
57
|
+
* }
|
|
58
|
+
*
|
|
59
|
+
* function TodoList() {
|
|
60
|
+
* const [todos, { addTodo }] = useContext(TodosContext); // typed as TodosCtx
|
|
61
|
+
* // ...
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```tsx
|
|
67
|
+
* // Primitive default — falls back to "light" outside a Provider.
|
|
68
|
+
* const ThemeContext = createContext<"light" | "dark">("light");
|
|
69
|
+
*
|
|
70
|
+
* function Button() {
|
|
71
|
+
* const theme = useContext(ThemeContext); // "light" | "dark"
|
|
72
|
+
* return <button class={theme}>Click</button>;
|
|
21
73
|
* }
|
|
22
|
-
* export function createContext<T>(
|
|
23
|
-
* defaultValue?: T,
|
|
24
|
-
* options?: { name?: string }
|
|
25
|
-
* ): Context<T | undefined>;
|
|
26
74
|
* ```
|
|
27
|
-
* @param defaultValue optional default to inject into context
|
|
28
|
-
* @param options allows to set a name in dev mode for debugging purposes
|
|
29
|
-
* @returns The context that contains the Provider Component and that can be used with `useContext`
|
|
30
75
|
*
|
|
31
76
|
* @description https://docs.solidjs.com/reference/component-apis/create-context
|
|
32
77
|
*/
|
|
33
|
-
export declare function createContext<T>(defaultValue?:
|
|
34
|
-
export declare function createContext<T>(defaultValue: T, options?: EffectOptions): Context<T>;
|
|
78
|
+
export declare function createContext<T>(defaultValue?: T, options?: EffectOptions): Context<T>;
|
|
35
79
|
/**
|
|
36
|
-
*
|
|
80
|
+
* Reads the current value of a context.
|
|
81
|
+
*
|
|
82
|
+
* - For `createContext<T>()` (default-less): returns the value from the
|
|
83
|
+
* nearest enclosing Provider, or throws `ContextNotFoundError` if none is
|
|
84
|
+
* mounted. Return type is `T` (no narrowing required).
|
|
85
|
+
* - For `createContext<T>(defaultValue)`: returns the value from the nearest
|
|
86
|
+
* enclosing Provider, or `defaultValue` if none is mounted.
|
|
37
87
|
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
88
|
+
* In Solid, `useContext` is the canonical way to read context. There is no
|
|
89
|
+
* need for a wrapper hook that throws on missing Provider — the default-less
|
|
90
|
+
* form already does that, and its return type is `T`.
|
|
91
|
+
*
|
|
92
|
+
* @param context a context returned from `createContext`
|
|
93
|
+
* @returns the value provided by the nearest enclosing Provider, or the
|
|
94
|
+
* default if one was supplied to `createContext`
|
|
95
|
+
* @throws `ContextNotFoundError` if no Provider is mounted and the context
|
|
96
|
+
* was created without a default
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```tsx
|
|
100
|
+
* const TodosContext = createContext<TodosCtx>();
|
|
101
|
+
*
|
|
102
|
+
* function TodoList() {
|
|
103
|
+
* const [todos, { addTodo }] = useContext(TodosContext); // throws if no Provider
|
|
104
|
+
* // ...
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
40
107
|
*
|
|
41
108
|
* @description https://docs.solidjs.com/reference/component-apis/use-context
|
|
42
109
|
*/
|
|
@@ -47,10 +114,20 @@ export type ChildrenReturn = Accessor<ResolvedChildren> & {
|
|
|
47
114
|
toArray: () => ResolvedJSXElement[];
|
|
48
115
|
};
|
|
49
116
|
/**
|
|
50
|
-
* Resolves
|
|
117
|
+
* Resolves a `children` accessor and exposes the result as an accessor with
|
|
118
|
+
* a `.toArray()` helper. Use this when a component needs to inspect or
|
|
119
|
+
* iterate over its children rather than just render them through.
|
|
51
120
|
*
|
|
52
121
|
* @param fn an accessor for the children
|
|
53
|
-
* @returns
|
|
122
|
+
* @returns an accessor of the resolved children, with `.toArray()` for iteration
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```tsx
|
|
126
|
+
* function List(props: { children: JSX.Element }) {
|
|
127
|
+
* const items = children(() => props.children);
|
|
128
|
+
* return <ul>{items.toArray().map(item => <li>{item}</li>)}</ul>;
|
|
129
|
+
* }
|
|
130
|
+
* ```
|
|
54
131
|
*
|
|
55
132
|
* @description https://docs.solidjs.com/reference/component-apis/children
|
|
56
133
|
*/
|
|
@@ -41,7 +41,21 @@ export declare function Repeat<T extends JSX.Element>(props: {
|
|
|
41
41
|
children: ((index: number) => T) | T;
|
|
42
42
|
}): JSX.Element;
|
|
43
43
|
/**
|
|
44
|
-
* Conditionally
|
|
44
|
+
* Conditionally renders its children when `when` is truthy, otherwise renders
|
|
45
|
+
* the optional `fallback`.
|
|
46
|
+
*
|
|
47
|
+
* The function-child form receives an accessor for the narrowed value — call
|
|
48
|
+
* it to read. Without `keyed` (default), the child is preserved across
|
|
49
|
+
* truthy values; with `keyed`, the child remounts whenever the value's
|
|
50
|
+
* identity changes.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```tsx
|
|
54
|
+
* <Show when={user()} fallback={<SignIn />}>
|
|
55
|
+
* {u => <Greeting name={u().name} />}
|
|
56
|
+
* </Show>
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
45
59
|
* @description https://docs.solidjs.com/reference/components/show
|
|
46
60
|
*/
|
|
47
61
|
export declare function Show<T, F extends ConditionalRenderCallback<T>>(props: {
|
|
@@ -74,12 +88,24 @@ export type MatchProps<T, F extends ConditionalRenderCallback<T> = ConditionalRe
|
|
|
74
88
|
children: ConditionalRenderChildren<T, F>;
|
|
75
89
|
};
|
|
76
90
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
91
|
+
* A branch inside a `<Switch>`. The first `<Match>` whose `when` is truthy
|
|
92
|
+
* wins; remaining matches are skipped.
|
|
93
|
+
*
|
|
94
|
+
* Like `<Show>`, `<Match>` supports a function child that receives an
|
|
95
|
+
* accessor for the narrowed value.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```tsx
|
|
99
|
+
* <Switch fallback={<NotFound />}>
|
|
100
|
+
* <Match when={user()}>
|
|
101
|
+
* {u => <Profile name={u().name} />}
|
|
102
|
+
* </Match>
|
|
103
|
+
* <Match when={loading()}>
|
|
104
|
+
* <Spinner />
|
|
105
|
+
* </Match>
|
|
106
|
+
* </Switch>
|
|
82
107
|
* ```
|
|
108
|
+
*
|
|
83
109
|
* @description https://docs.solidjs.com/reference/components/switch-and-match
|
|
84
110
|
*/
|
|
85
111
|
export declare function Match<T, F extends ConditionalRenderCallback<T>>(props: MatchProps<T, F>): JSX.Element;
|
|
@@ -103,14 +129,40 @@ export declare function Errored(props: {
|
|
|
103
129
|
children: JSX.Element;
|
|
104
130
|
}): JSX.Element;
|
|
105
131
|
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
132
|
+
* Renders a `fallback` while pending async reads inside the subtree settle.
|
|
133
|
+
*
|
|
134
|
+
* Any computation (`createMemo`, `createSignal(fn)`, `createStore(fn)`,
|
|
135
|
+
* `lazy(...)`, etc.) that throws because data isn't ready is caught by the
|
|
136
|
+
* nearest enclosing `<Loading>`. The boundary swaps to its `fallback` until
|
|
137
|
+
* every pending read has resolved, then renders the children.
|
|
138
|
+
*
|
|
139
|
+
* The optional `on` prop scopes the boundary so it ignores transitions
|
|
140
|
+
* caused by writes to other reactive sources — those transitions stay on the
|
|
141
|
+
* previous content (with `isPending()` flipping during the transition).
|
|
142
|
+
*
|
|
143
|
+
* Scope `<Loading>` around the data-dependent slot, not the surrounding
|
|
144
|
+
* shell. Wrapping layout chrome (header, nav, footer) in the same boundary
|
|
145
|
+
* as the data means revalidation replaces the entire screen with the
|
|
146
|
+
* fallback; rendering chrome outside the boundary keeps it stable while
|
|
147
|
+
* only the affordance flips.
|
|
109
148
|
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```tsx
|
|
151
|
+
* const Profile = lazy(() => import("./Profile"));
|
|
152
|
+
*
|
|
153
|
+
* <Loading fallback={<Spinner />}>
|
|
154
|
+
* <Profile />
|
|
112
155
|
* </Loading>
|
|
113
156
|
* ```
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```tsx
|
|
160
|
+
* // Only show the fallback for transitions caused by writes to `route`.
|
|
161
|
+
* <Loading fallback={<Skeleton />} on={route}>
|
|
162
|
+
* <Page />
|
|
163
|
+
* </Loading>
|
|
164
|
+
* ```
|
|
165
|
+
*
|
|
114
166
|
* @description https://docs.solidjs.com/reference/components/suspense
|
|
115
167
|
*/
|
|
116
168
|
export declare function Loading(props: {
|