@typewirets/react 0.1.0 → 0.2.0
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/CHANGELOG.md +28 -0
- package/README.md +87 -1
- package/dist/cjs/index.d.ts +235 -2
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +330 -34
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/package.json +1 -0
- package/dist/esm/index.d.ts +235 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +329 -34
- package/dist/esm/index.js.map +1 -1
- package/dist/types/index.d.ts +235 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +329 -34
- package/dist/types/index.js.map +1 -1
- package/package.json +11 -10
- package/src/index.tsx +0 -111
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
- Depends on `@typewirets/core` 0.2.0.
|
|
6
|
+
- **`useTypeWire` returns preloaded falsy values.** It ended with `if (value) return value`, so a preloaded `0`, `""`, `false` or `null` suspended as if it weren't ready, and the fallback showed. It now tells "not ready" apart from a falsy value.
|
|
7
|
+
- **New: `usePreload({ wires })`.** Suspends the calling component until every singleton in `wires` is created, in parallel, so components below it read them with `useTypeWire` without suspending: one fallback for a route or feature instead of one per wire. Skips wires that aren't singletons; a failed creation reaches the nearest error boundary. Works with any resolution context. New type: `UsePreloadOpts`.
|
|
8
|
+
- **New: `useTypeWire(wire, { suspend: false })`.** Throws a `TypeWireError` with reason `NotPreloaded`, naming the wire, instead of suspending when the value isn't created yet, so a forgotten preload shows up at once. The default still suspends. New type: `UseTypeWireOpts`.
|
|
9
|
+
- The README leads with preloading: `container.preload` before the first render, `usePreload` per route or feature, and Suspense for wires nobody preloaded.
|
|
10
|
+
- **`useTypeWire` creates a `createWith` singleton once on first mount.** With `@typewirets/core` before this release, one reader created it twice, two readers in one Suspense boundary three times, and one reader under `StrictMode` four times. The fix is in core; upgrade `@typewirets/core` and `@typewirets/react` together ([#21](https://github.com/typewirets/typewirets/issues/21)).
|
|
11
|
+
- **A component no longer gets a creation started before `unbind`.** `ReactResolutionContext` kept its own map of in-flight `get` calls. After `container.unbind(type)` and a re-apply, a component that mounted while the old creation was still pending got the old binding's value, or waited forever if that creation never finished. The map is gone; `@typewirets/core` already shares one in-flight creation per singleton and keeps creations from before `unbind` away from new callers. Two side effects:
|
|
12
|
+
- A custom `ResolutionContext` passed to `ResolutionContextProvider` must now share one in-flight creation per singleton itself, or readers may get different instances. `TypeWireContainer` and the `@typewirets/inversify` adapter both do.
|
|
13
|
+
- Concurrent `get` calls through `useContainer()` for a *transient* async wire no longer share one instance.
|
|
14
|
+
- **Re-rendering `ResolutionContextProvider` keeps cached errors and the context value.** The provider used to build a new `ReactResolutionContext` on every render. Any re-render cleared the error cache, so failing wires were created again, and every consumer got a new context value. With a Suspense boundary above the provider, a failing async wire was created again on every retry, forever. The provider now uses one wrapper per context.
|
|
15
|
+
- **New: `ReactResolutionContext.clearErrors(typeSymbol?)`.** A cached resolution error lasts until you clear it, including after `unbind` and a re-apply, because the cache can't tell that a binding changed. To retry, pass your own `ReactResolutionContext` to the provider, call `clearErrors` after replacing the binding, and reset the error boundary. A failure that settles after `clearErrors` is not cached. See "When a resolution fails" in the README.
|
|
16
|
+
- **Node.js 22 or later is required.** `engines.node` is now `>=22`, because Node.js 20 reached end-of-life on 30 April 2026. CI tests Node.js 22, 24 and 26.
|
|
17
|
+
|
|
18
|
+
### Also in this release: changes prepared as 0.1.1, which was never published
|
|
19
|
+
|
|
20
|
+
- **CommonJS `require()` works.** The package is `"type": "module"`, so Node loaded the CommonJS build in `dist/cjs` as an ES module: `require()` from plain Node (TypeScript compiled to CommonJS, ts-node) threw `ReferenceError: exports is not defined`. Bundlers, Jest and ESM `import` were not affected. The build now writes `dist/cjs/package.json` with `{"type":"commonjs"}`.
|
|
21
|
+
|
|
22
|
+
## 0.2.0-rc.1
|
|
23
|
+
|
|
24
|
+
Release candidate for 0.2.0, with the same changes. They are listed under 0.2.0.
|
|
25
|
+
|
|
26
|
+
## 0.1.0
|
|
27
|
+
|
|
28
|
+
- Initial release.
|
package/README.md
CHANGED
|
@@ -33,6 +33,10 @@ async function main() {
|
|
|
33
33
|
|
|
34
34
|
// Apply all wires to the container at once
|
|
35
35
|
await wireGroup.apply(container);
|
|
36
|
+
|
|
37
|
+
// Create them before the first render, so components read them
|
|
38
|
+
// synchronously and no Suspense fallback appears
|
|
39
|
+
await container.preload({ wires: wireGroup.wires });
|
|
36
40
|
|
|
37
41
|
// Render your React app with the container
|
|
38
42
|
const rootEl = document.getElementById("root");
|
|
@@ -149,9 +153,50 @@ export function UserList() {
|
|
|
149
153
|
}
|
|
150
154
|
```
|
|
151
155
|
|
|
156
|
+
## Preloading
|
|
157
|
+
|
|
158
|
+
React renders synchronously, but getting a TypeWire's value is async: any creator, or an override applied later, may be async. Preloading does that waiting at your app's own boundaries, so components read values synchronously:
|
|
159
|
+
|
|
160
|
+
| Where | How | What the user sees |
|
|
161
|
+
|---|---|---|
|
|
162
|
+
| Before the first render | `await container.preload({ wires })` (or `container.preload()` for every singleton) | No fallback at all |
|
|
163
|
+
| Where a part of the app starts (a route, a panel, a feature) | `usePreload({ wires })` under one `<Suspense>` | One fallback for the whole set, then the subtree renders without suspending again |
|
|
164
|
+
| Nowhere | `useTypeWire` suspends on first use | A fallback each place a wire is first read |
|
|
165
|
+
|
|
166
|
+
```tsx
|
|
167
|
+
import { usePreload, useTypeWire } from "@typewirets/react";
|
|
168
|
+
|
|
169
|
+
function ReportsRoute() {
|
|
170
|
+
// Suspends once, until both are created (in parallel)
|
|
171
|
+
usePreload({ wires: [ReportsServiceWire, ChartsWire] });
|
|
172
|
+
return <ReportsPage />;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function ReportsPage() {
|
|
176
|
+
const reports = useTypeWire(ReportsServiceWire); // already created: no suspend
|
|
177
|
+
return <ReportList reports={reports} />;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
<Suspense fallback={<div>Loading reports...</div>}>
|
|
181
|
+
<ReportsRoute />
|
|
182
|
+
</Suspense>
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
`usePreload` skips wires that aren't singletons, works with any resolution context (including the Inversify adapter), and sends a failed creation to the nearest error boundary.
|
|
186
|
+
|
|
187
|
+
### Catching a forgotten preload
|
|
188
|
+
|
|
189
|
+
If your app preloads every phase and should never show a fallback, pass `{ suspend: false }`. A wire that isn't created yet then throws a `TypeWireError` with reason `NotPreloaded`, naming the wire, instead of suspending:
|
|
190
|
+
|
|
191
|
+
```tsx
|
|
192
|
+
const userStore = useTypeWire(UserStoreWire, { suspend: false });
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Preloaded values render as they are, including `0`, `""`, `false` and `null`.
|
|
196
|
+
|
|
152
197
|
## Handling Async TypeWires
|
|
153
198
|
|
|
154
|
-
|
|
199
|
+
A wire nobody preloaded still works: React Suspense handles the loading state:
|
|
155
200
|
|
|
156
201
|
```tsx
|
|
157
202
|
// Component that depends on an async TypeWire
|
|
@@ -176,10 +221,50 @@ function App({ container }) {
|
|
|
176
221
|
}
|
|
177
222
|
```
|
|
178
223
|
|
|
224
|
+
### When a resolution fails
|
|
225
|
+
|
|
226
|
+
If an async TypeWire fails, `useTypeWire` throws the error to the nearest error boundary. The error is cached, so React's Suspense retries don't start the creation again and again. Re-rendering or remounting `ResolutionContextProvider` keeps the cache: the provider uses one `ReactResolutionContext` per container.
|
|
227
|
+
|
|
228
|
+
The cache can't tell that a binding was replaced, so a cached error lasts until you clear it, even after `unbind` and a re-apply. To retry, create the `ReactResolutionContext` yourself, then clear its errors after replacing the binding and reset the error boundary:
|
|
229
|
+
|
|
230
|
+
```tsx
|
|
231
|
+
import { ReactResolutionContext, ResolutionContextProvider } from "@typewirets/react";
|
|
232
|
+
|
|
233
|
+
const resolution = new ReactResolutionContext(container);
|
|
234
|
+
|
|
235
|
+
function App() {
|
|
236
|
+
const [attempt, setAttempt] = useState(0);
|
|
237
|
+
|
|
238
|
+
async function retry() {
|
|
239
|
+
await container.unbind(UserStoreWire.type);
|
|
240
|
+
await UserStoreWire.apply(container);
|
|
241
|
+
resolution.clearErrors(UserStoreWire.type);
|
|
242
|
+
setAttempt((n) => n + 1); // a new key resets the error boundary
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return (
|
|
246
|
+
<ResolutionContextProvider resolutionContext={resolution}>
|
|
247
|
+
<ErrorBoundary key={attempt} fallback={<button onClick={retry}>Retry</button>}>
|
|
248
|
+
<Suspense fallback={<div>Loading dashboard...</div>}>
|
|
249
|
+
<UserDashboard />
|
|
250
|
+
</Suspense>
|
|
251
|
+
</ErrorBoundary>
|
|
252
|
+
</ResolutionContextProvider>
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
`ErrorBoundary` stands for any error boundary component. `clearErrors()` with no argument clears every cached error.
|
|
258
|
+
|
|
259
|
+
### Custom resolution contexts
|
|
260
|
+
|
|
261
|
+
`ResolutionContextProvider` accepts any `ResolutionContext`. It doesn't merge concurrent requests itself, so the context must share one in-flight creation per singleton, or components may get different instances. `TypeWireContainer` and the `@typewirets/inversify` adapter both do.
|
|
262
|
+
|
|
179
263
|
## Core Components
|
|
180
264
|
|
|
181
265
|
- **ResolutionContextProvider**: Provides TypeWire container to React components
|
|
182
266
|
- **useTypeWire**: Hook to access TypeWire instances in components
|
|
267
|
+
- **usePreload**: Hook that suspends a subtree once, until a set of wires is created
|
|
183
268
|
- **useContainer**: Direct access to the ResolutionContext (advanced use cases)
|
|
184
269
|
|
|
185
270
|
## Best Practices
|
|
@@ -187,6 +272,7 @@ function App({ container }) {
|
|
|
187
272
|
1. **Initialize TypeWires in a main function**:
|
|
188
273
|
- Group your TypeWires with `typeWireGroupOf`
|
|
189
274
|
- Apply them all at once before rendering
|
|
275
|
+
- Preload what the first screen needs with `container.preload({ wires })`; preload later phases with `usePreload`
|
|
190
276
|
|
|
191
277
|
2. **Use state management libraries with TypeWire**:
|
|
192
278
|
- Zustand, Redux, or MobX work well with TypeWire
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,14 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeWire React Integration
|
|
3
|
+
*
|
|
4
|
+
* Provides React bindings for TypeWire dependency injection, enabling
|
|
5
|
+
* context-based dependency resolution within React component trees.
|
|
6
|
+
*
|
|
7
|
+
* Key exports:
|
|
8
|
+
* - {@link ReactResolutionContext} — Wraps a `ResolutionContext` with error caching, so a failed resolution doesn't loop under Suspense
|
|
9
|
+
* - {@link ContainerContext} — React Context holding the active resolution context
|
|
10
|
+
* - {@link useContainer} — Hook to access the current resolution context
|
|
11
|
+
* - {@link useTypeWire} — Hook to resolve a TypeWire with React Suspense support
|
|
12
|
+
* - {@link usePreload} — Hook that suspends a subtree once until a set of wires is created
|
|
13
|
+
* - {@link ResolutionContextProvider} — Component that provides a resolution context to the tree
|
|
14
|
+
*
|
|
15
|
+
* @packageDocumentation
|
|
16
|
+
*/
|
|
1
17
|
import * as React from "react";
|
|
2
|
-
import { type ResolutionContext, type TypeSymbol, type TypeWire } from "@typewirets/core";
|
|
18
|
+
import { type AnyTypeSymbol, type AnyTypeWire, type ResolutionContext, type TypeSymbol, type TypeWire } from "@typewirets/core";
|
|
19
|
+
/**
|
|
20
|
+
* A React-aware wrapper around {@link ResolutionContext} that caches resolution
|
|
21
|
+
* errors.
|
|
22
|
+
*
|
|
23
|
+
* When a component suspends on a resolution that then fails, React renders it
|
|
24
|
+
* again, and that render would start a new creation, suspend, fail and repeat
|
|
25
|
+
* forever. To stop that loop, the error from a failed `get` is cached, and
|
|
26
|
+
* later `get` and `getSync` calls for the same `TypeSymbol` throw it without
|
|
27
|
+
* calling the underlying context.
|
|
28
|
+
*
|
|
29
|
+
* A cached error lasts until {@link ReactResolutionContext.clearErrors} is
|
|
30
|
+
* called, even across `unbind` and a re-apply: this class only sees a
|
|
31
|
+
* `ResolutionContext`, so it cannot tell that a binding changed. To retry
|
|
32
|
+
* after replacing a binding, call `clearErrors` and then reset the error
|
|
33
|
+
* boundary that caught the error.
|
|
34
|
+
*
|
|
35
|
+
* Calls that run while a resolution is in flight are not deduplicated here.
|
|
36
|
+
* The underlying context must share one in-flight creation per singleton
|
|
37
|
+
* itself, or readers may get different instances. `TypeWireContainer` does,
|
|
38
|
+
* and never hands a creation started before `unbind` to new callers. So does
|
|
39
|
+
* the `@typewirets/inversify` adapter, because Inversify 7 shares concurrent
|
|
40
|
+
* singleton `getAsync` calls. A custom `ResolutionContext` must do the same.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const container = new TypeWireContainer();
|
|
45
|
+
* const context = new ReactResolutionContext(container);
|
|
46
|
+
* const value = await context.get(MySymbol);
|
|
47
|
+
*
|
|
48
|
+
* // After replacing the binding for MySymbol:
|
|
49
|
+
* context.clearErrors(MySymbol);
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
3
52
|
export declare class ReactResolutionContext {
|
|
4
53
|
#private;
|
|
5
54
|
constructor(resolutionContext: ResolutionContext);
|
|
55
|
+
/**
|
|
56
|
+
* Synchronously retrieves a resolved instance for the given type symbol.
|
|
57
|
+
*
|
|
58
|
+
* @template T The type of the resolved instance
|
|
59
|
+
* @param typeSymbol - The typed symbol identifying the dependency to resolve
|
|
60
|
+
* @returns The resolved instance
|
|
61
|
+
* @throws Re-throws the cached error if a previous async resolution for this symbol failed
|
|
62
|
+
* @throws Throws if the instance has not been resolved yet (see {@link ResolutionContext.getSync})
|
|
63
|
+
*/
|
|
6
64
|
getSync<T>(typeSymbol: TypeSymbol<T>): T;
|
|
65
|
+
/**
|
|
66
|
+
* Asynchronously resolves an instance for the given type symbol.
|
|
67
|
+
*
|
|
68
|
+
* If a previous resolution for this symbol failed, the cached error is
|
|
69
|
+
* thrown immediately. Otherwise the call goes to the underlying context,
|
|
70
|
+
* which joins a creation already in flight for a singleton.
|
|
71
|
+
*
|
|
72
|
+
* @template T The type of the resolved instance
|
|
73
|
+
* @param typeSymbol - The typed symbol identifying the dependency to resolve
|
|
74
|
+
* @returns A promise that resolves to the instance
|
|
75
|
+
* @throws Re-throws the cached error if a previous resolution for this symbol failed
|
|
76
|
+
*/
|
|
7
77
|
get<T>(typeSymbol: TypeSymbol<T>): Promise<T>;
|
|
78
|
+
/**
|
|
79
|
+
* Forgets cached resolution errors, so the next `get` or `getSync` asks the
|
|
80
|
+
* underlying context again.
|
|
81
|
+
*
|
|
82
|
+
* Call it after replacing a failed binding (`unbind`, then apply the wire
|
|
83
|
+
* again), then reset the error boundary that shows the error. A failure that
|
|
84
|
+
* was still in flight when you call this is not cached when it settles.
|
|
85
|
+
*
|
|
86
|
+
* @param typeSymbol - The symbol whose error to forget. Omit to forget all.
|
|
87
|
+
*/
|
|
88
|
+
clearErrors(typeSymbol?: AnyTypeSymbol): void;
|
|
8
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* React Context that holds the active {@link ResolutionContext} for the component tree.
|
|
92
|
+
*
|
|
93
|
+
* The default value is an empty {@link TypeWireContainer} wrapped in a
|
|
94
|
+
* {@link ReactResolutionContext}. In practice, you should provide your own
|
|
95
|
+
* container via {@link ResolutionContextProvider}.
|
|
96
|
+
*/
|
|
9
97
|
export declare const ContainerContext: React.Context<ResolutionContext>;
|
|
98
|
+
/**
|
|
99
|
+
* Hook to access the current {@link ResolutionContext} from the nearest
|
|
100
|
+
* {@link ResolutionContextProvider}.
|
|
101
|
+
*
|
|
102
|
+
* @returns The current resolution context
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```tsx
|
|
106
|
+
* function MyComponent() {
|
|
107
|
+
* const container = useContainer();
|
|
108
|
+
* // Use container for manual resolution if needed
|
|
109
|
+
* }
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
10
112
|
export declare function useContainer(): ResolutionContext;
|
|
11
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Options for {@link useTypeWire}.
|
|
115
|
+
*/
|
|
116
|
+
export interface UseTypeWireOpts {
|
|
117
|
+
/**
|
|
118
|
+
* What to do when the value isn't created yet. `true` (the default)
|
|
119
|
+
* suspends until it is, so the nearest `<Suspense>` shows its fallback.
|
|
120
|
+
* `false` throws a `TypeWireError` with reason `NotPreloaded` naming the
|
|
121
|
+
* wire instead, for apps that preload every phase and never want a
|
|
122
|
+
* fallback: a forgotten preload then shows up at once, in development.
|
|
123
|
+
*/
|
|
124
|
+
suspend?: boolean;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Hook that resolves a {@link TypeWire} within the current container context,
|
|
128
|
+
* with React Suspense integration.
|
|
129
|
+
*
|
|
130
|
+
* Resolution behavior:
|
|
131
|
+
* 1. **Sync available** — If the wire can be resolved synchronously (e.g., a singleton
|
|
132
|
+
* that was already created or preloaded), the value is returned immediately,
|
|
133
|
+
* including falsy values such as `0`, `""`, `false` and `null`.
|
|
134
|
+
* 2. **Async pending** — If sync resolution fails with a retriable error, the hook
|
|
135
|
+
* starts an async resolution and throws the promise to trigger React Suspense.
|
|
136
|
+
* With `{ suspend: false }` it throws a `TypeWireError` with reason
|
|
137
|
+
* `NotPreloaded` instead.
|
|
138
|
+
* 3. **Error** — If sync resolution fails with a non-retriable error, it is re-thrown.
|
|
139
|
+
*
|
|
140
|
+
* To render without a fallback, preload the wires first, with
|
|
141
|
+
* `container.preload` before rendering or {@link usePreload} higher in the
|
|
142
|
+
* tree. A wire nobody preloaded suspends, so this hook must be used inside a
|
|
143
|
+
* `<Suspense>` boundary unless you pass `{ suspend: false }`.
|
|
144
|
+
*
|
|
145
|
+
* @template T The type of the resolved instance
|
|
146
|
+
* @param typeWire - The TypeWire to resolve
|
|
147
|
+
* @param opts - Optional settings; see {@link UseTypeWireOpts}
|
|
148
|
+
* @returns The resolved instance
|
|
149
|
+
* @throws The resolution promise when the value is not yet available (for Suspense)
|
|
150
|
+
* @throws {@link TypeWireError} with reason `NotPreloaded` when the value is not yet available and `suspend` is `false`
|
|
151
|
+
* @throws {@link TypeWireError} if synchronous resolution fails with a non-retriable error
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```tsx
|
|
155
|
+
* function UserProfile() {
|
|
156
|
+
* const userService = useTypeWire(UserServiceWire);
|
|
157
|
+
* return <div>{userService.getName()}</div>;
|
|
158
|
+
* }
|
|
159
|
+
*
|
|
160
|
+
* // Preloaded before rendering: no fallback.
|
|
161
|
+
* await container.preload({ wires: [UserServiceWire] });
|
|
162
|
+
*
|
|
163
|
+
* // Or wrap in Suspense for wires that may not be ready yet.
|
|
164
|
+
* <Suspense fallback={<Loading />}>
|
|
165
|
+
* <UserProfile />
|
|
166
|
+
* </Suspense>
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
export declare function useTypeWire<T>(typeWire: TypeWire<T>, opts?: UseTypeWireOpts): T;
|
|
170
|
+
/**
|
|
171
|
+
* Options for {@link usePreload}.
|
|
172
|
+
*/
|
|
173
|
+
export interface UsePreloadOpts {
|
|
174
|
+
/**
|
|
175
|
+
* The wires to create before the calling component renders. Their imports
|
|
176
|
+
* are created with them. Wires that aren't singletons are skipped. To
|
|
177
|
+
* preload a group, pass its `wires`.
|
|
178
|
+
*/
|
|
179
|
+
wires: readonly AnyTypeWire[];
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Hook that suspends the calling component until every singleton in
|
|
183
|
+
* `opts.wires` is created, so components below it read them with
|
|
184
|
+
* {@link useTypeWire} without suspending.
|
|
185
|
+
*
|
|
186
|
+
* Use it where a part of the app starts (a route, a panel, a feature), under
|
|
187
|
+
* one `<Suspense>` boundary: the fallback shows once for the whole set, and
|
|
188
|
+
* the creations run in parallel. A creation that fails reaches the nearest
|
|
189
|
+
* error boundary.
|
|
190
|
+
*
|
|
191
|
+
* It works with any resolution context, including the Inversify adapter.
|
|
192
|
+
* Outside React, use `container.preload` instead.
|
|
193
|
+
*
|
|
194
|
+
* @param opts - The wires to preload; see {@link UsePreloadOpts}
|
|
195
|
+
* @throws A promise while any of the wires is still being created (for Suspense)
|
|
196
|
+
* @throws The creation's error, once one has failed
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```tsx
|
|
200
|
+
* function ReportsRoute() {
|
|
201
|
+
* usePreload({ wires: [reportsServiceWire, chartsWire] });
|
|
202
|
+
* return <ReportsPage />;
|
|
203
|
+
* }
|
|
204
|
+
*
|
|
205
|
+
* <Suspense fallback={<Loading />}>
|
|
206
|
+
* <ReportsRoute />
|
|
207
|
+
* </Suspense>
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
export declare function usePreload(opts: UsePreloadOpts): void;
|
|
211
|
+
/**
|
|
212
|
+
* React component that provides a {@link ResolutionContext} to the component tree.
|
|
213
|
+
*
|
|
214
|
+
* If the given `resolutionContext` is not already a {@link ReactResolutionContext},
|
|
215
|
+
* it is wrapped in one, so a failed resolution reaches an error boundary
|
|
216
|
+
* instead of retrying under Suspense. Each plain context gets one wrapper,
|
|
217
|
+
* reused on every render and every mount, so re-rendering the provider keeps
|
|
218
|
+
* cached errors and gives consumers the same context value.
|
|
219
|
+
*
|
|
220
|
+
* A cached error lasts until `clearErrors` is called, even after `unbind` and
|
|
221
|
+
* a re-apply. To be able to retry, create the {@link ReactResolutionContext}
|
|
222
|
+
* yourself, pass it here, and call its `clearErrors` after replacing the
|
|
223
|
+
* binding.
|
|
224
|
+
*
|
|
225
|
+
* The context must share one in-flight creation per singleton (as
|
|
226
|
+
* `TypeWireContainer` does); see {@link ReactResolutionContext}.
|
|
227
|
+
*
|
|
228
|
+
* @param props.resolutionContext - The resolution context to provide to descendants
|
|
229
|
+
* @param props.children - Child components that will have access to the context
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```tsx
|
|
233
|
+
* async function main() {
|
|
234
|
+
* const container = new TypeWireContainer();
|
|
235
|
+
* await AppWireGroup.apply(container);
|
|
236
|
+
*
|
|
237
|
+
* createRoot(document.getElementById('root')!).render(
|
|
238
|
+
* <ResolutionContextProvider resolutionContext={container}>
|
|
239
|
+
* <App />
|
|
240
|
+
* </ResolutionContextProvider>
|
|
241
|
+
* );
|
|
242
|
+
* }
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
12
245
|
export declare function ResolutionContextProvider(props: {
|
|
13
246
|
resolutionContext: ResolutionContext;
|
|
14
247
|
children?: React.ReactNode;
|
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,UAAU,EACf,KAAK,QAAQ,EAGd,MAAM,kBAAkB,CAAC;AAE1B,qBAAa,sBAAsB;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,UAAU,EACf,KAAK,QAAQ,EAGd,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBAAa,sBAAsB;;gBAYrB,iBAAiB,EAAE,iBAAiB;IAIhD;;;;;;;;OAQG;IACH,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC;IAOxC;;;;;;;;;;;OAWG;IACG,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAmBnD;;;;;;;;;OASG;IACH,WAAW,CAAC,UAAU,CAAC,EAAE,aAAa,GAAG,IAAI;CAoB9C;AA2BD;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,kCAE5B,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,sBAG3B;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AA6CD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,IAAI,CAAC,EAAE,eAAe,GACrB,CAAC,CA6CH;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,KAAK,EAAE,SAAS,WAAW,EAAE,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CAgBrD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE;IAC/C,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B,2CAOA"}
|