@@ -9,9 +9,11 @@ title: State Management
|
|||||||
scopes. The usual pattern is:
|
scopes. The usual pattern is:
|
||||||
|
|
||||||
1. Create state with Effect primitives such as `SubscriptionRef`.
|
1. Create state with Effect primitives such as `SubscriptionRef`.
|
||||||
2. Expose read-only reactive state as a `Subscribable`.
|
2. Turn the Effect primitive into a `Lens` with the matching constructor, such
|
||||||
3. Expose read/write reactive state as a `Lens`.
|
as `Lens.fromSubscriptionRef`.
|
||||||
4. Bind values into components with `Subscribable.useAll`.
|
3. Expose read-only reactive state as a `Subscribable`.
|
||||||
|
4. Expose read/write reactive state as a `Lens`.
|
||||||
|
5. Bind values into components with `Subscribable.useAll`.
|
||||||
|
|
||||||
`effect-fc` re-exports the `Lens` and `Subscribable` modules from
|
`effect-fc` re-exports the `Lens` and `Subscribable` modules from
|
||||||
[`effect-lens`](https://github.com/Thiladev/effect-lens) for convenience. The
|
[`effect-lens`](https://github.com/Thiladev/effect-lens) for convenience. The
|
||||||
@@ -102,9 +104,7 @@ const CounterReadOnlyView = Component.make("CounterReadOnly")(
|
|||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
Use `Subscribable.useAll` instead of subscribing manually. It reads the current
|
`Subscribable.useAll` reads the current values during render and uses scoped subscriptions to update React state when changes arrive.
|
||||||
values during render and uses scoped subscriptions to update React state when
|
|
||||||
changes arrive.
|
|
||||||
|
|
||||||
## Lenses
|
## Lenses
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user