You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All three peers are required. `@illuma/signals` is only used by the `/signals`
28
+
entry point, but it is declared as a plain peer dependency, so a package manager
29
+
will ask for it either way.
30
+
18
31
Requires `@illuma/core` 2.5.0 or newer: scopes are built on the container's
19
32
`weakParentLink` option, so that a container React builds during a render it later
20
33
throws away can be collected instead of being retained by its parent forever.
21
34
22
35
## Structure
23
36
24
-
-`@illuma/react-experimental` – Dependency injection bindings and React integration
25
-
-`@illuma/react-experimental/signals` – Signals implementation for state management outside of React's render cycle
26
-
-`@illuma/react-experimental/testkit` – Container-backed wrapper for testing components
37
+
-`@illuma/react-experimental` – dependency injection bindings and React integration
38
+
-`@illuma/react-experimental/signals` – re-exports `@illuma/signals` and adds the `useSignal` hook
39
+
-`@illuma/react-experimental/testkit` – container-backed wrapper for testing components
40
+
41
+
## Example
42
+
43
+
[`example/`](./example) is a small application that puts every section of this
44
+
document into one tree — a root container, a scope per screen, a service that
45
+
owns a subscription, signals rendered through `useSignal`, a subtree that
46
+
rebinds one token, and a test that swaps that token for a fake. It builds, runs
47
+
and tests:
48
+
49
+
```bash
50
+
bun run build # the package
51
+
cd example && npx vite # http://localhost:5175
52
+
cd example && npx vitest run # 6 tests
53
+
```
27
54
28
55
## Setup
29
56
@@ -43,6 +70,10 @@ export const App = () => (
43
70
);
44
71
```
45
72
73
+
Keep that array module-level. `providers` is read once, when the container is
74
+
built; a fresh literal on every render would be silently ignored, and the
75
+
adapter says so in development.
76
+
46
77
## Dependency Injection
47
78
48
79
A detailed guide on how **@illuma/core** DI system works can be found in the [Docs](https://github.com/git-illuma/core/blob/main/docs/GETTING_STARTED.md).
In this example, `FeatureSection` and its children will use `MockUserService`, while `Dashboard` and its children (`DashboardComponent`) will use the original `UserService`.
124
155
156
+
Overriding means shadowing in a *child* container. Listing two providers for one
157
+
token in the same container is an error, not a last-one-wins — which is worth
158
+
knowing when you lay out a provider array you also intend to reuse in tests.
159
+
125
160
### Resolution Modifiers
126
161
127
162
`useDependency` forwards the container's modifiers.
@@ -139,9 +174,13 @@ throws — a broken dependency is a bug, not an absent one.
139
174
140
175
Two rules matter, and both come from the container rather than from React.
141
176
142
-
**A constructor runs twice.** The container executes each factory once against proxy
143
-
dependencies to measure the graph, then once for real. A constructor must therefore be
144
-
pure: build fields, inject dependencies, and nothing else.
177
+
**A constructor runs more than once.** The container executes each factory once
178
+
against proxy dependencies to measure the graph, then once for real — and React
179
+
is free to build a container it later discards, which buys another pair. Under
180
+
`StrictMode` a provider's constructor is observed to run three times for the one
181
+
instance that survives. The number is not a contract; the rule it forces is.
182
+
A constructor may build fields and inject dependencies, and must cause nothing
183
+
to happen.
145
184
146
185
**Resources belong to the mount, not to the constructor.** React may render a component,
147
186
build its container, and then discard the whole attempt without ever committing it — and
0 commit comments