@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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAIL,aAAa,EACb,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAE1B,MAAM,OAAO,sBAAsB;IAKjC,YAAY,iBAAoC;QAJvC,4DAAsC;QACtC,8CAA8C,IAAI,GAAG,EAAE,EAAC;QACxD,mDAA0C,IAAI,GAAG,EAAE,EAAC;QAG3D,uBAAA,IAAI,6CAAsB,iBAAiB,MAAA,CAAC;IAC9C,CAAC;IAED,OAAO,CAAI,UAAyB;QAClC,IAAI,uBAAA,IAAI,gDAAkB,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YAClD,MAAM,uBAAA,IAAI,gDAAkB,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACtD,CAAC;QACD,OAAO,uBAAA,IAAI,iDAAmB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACrD,CAAC;IAED,KAAK,CAAC,GAAG,CAAI,UAAyB;QACpC,IAAI,uBAAA,IAAI,gDAAkB,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YAClD,MAAM,uBAAA,IAAI,gDAAkB,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACtD,CAAC;QAED,MAAM,OAAO,GAAG,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAe,CAAC;QACvE,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,OAAO,CAAC;QACjB,CAAC;QAED,MAAM,aAAa,GAAG,uBAAA,IAAI,iDAAmB,CAAC,GAAG,C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O,CACL,KAAC,gBAAgB,IAAC,KAAK,EAAE,iBAAiB,YACvC,KAAK,CAAC,QAAQ,GACE,CACpB,CAAC;AACJ,CAAC"}
@@ -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
- export declare function useTypeWire<T>(typeWire: TypeWire<T>): T;
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;
@@ -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;;gBAKrB,iBAAiB,EAAE,iB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