Fix README
Lint / lint (push) Successful in 25s

This commit is contained in:
Julien Valverdé
2026-07-16 22:25:54 +02:00
parent 673e413254
commit dcba13e8ea
2 changed files with 15 additions and 14 deletions
+1 -1
View File
@@ -247,7 +247,7 @@ const ref = yield* SubscriptionRef.make<{
const logUserCount = (users: View.View<readonly User[]>) =>
Effect.gen(function*() {
const userCount = View.map(users, users => users.length)
const userCount = View.focusArrayLength(users)
yield* Console.log(`There are ${yield* View.get(userCount)} users`)
yield* Stream.runForEach(
View.changes(userCount),
+14 -13
View File
@@ -239,30 +239,31 @@ const nameLens = lens.pipe(
### Subscribable
Lens implements both Effect's `Subscribable` and `Readable`, which you can use as a constraint to allow some parts of your app to only read and subscribe to the Lenses you provide them:
Effect's `Subscribable` is a read-only, reactive view of a value: it lets you read the current value and observe subsequent changes. Every `Lens` implements both `Subscribable` and `Readable`, which you can use as constraints to allow some parts of your app to only read and subscribe to the Lenses you provide them:
```typescript
const ref = yield* SubscriptionRef.make<{
readonly users: readonly User[]
}>({ users: [...] })
}>({ users: [] })
const someFunctionThatShouldOnlyHaveReadonlyAccessToTheState = (
usersSub: Subscribable.Subscribable<readonly User[], never, never>
) => Effect.gen(function*() {
// Do whatever
const usersCountSub = Subscribable.map(usersSub, a => a.length)
const users = yield* usersSub.get
yield* Effect.forkScoped(Stream.runForEach(usersSub.changes, ...))
})
const logUserCount = (users: Subscribable.Subscribable<readonly User[]>) =>
Effect.gen(function*() {
const userCount = Subscribable.focusArrayLength(users)
yield* Console.log(`There are ${yield* userCount.get} users`)
yield* Stream.runForEach(
userCount.changes,
count => Console.log(`There are now ${count} users`),
)
})
const lens = ref.pipe(
const usersLens = ref.pipe(
Lens.fromSubscriptionRef,
Lens.focusObjectOn("users"),
)
yield* someFunctionThatShouldOnlyHaveReadonlyAccessToTheState(lens)
yield* Effect.forkScoped(logUserCount(usersLens))
```
#### Focusing
This library re-exports Effect's `Subscribable` module and adds error transforms and recovery (`catchAll`, `catchAllCause`, `orElse`, `orElseSucceed`, and `retry`), plus transforms to narrow the focus of `Subscribable`'s, same as Lenses:
Subscribables can be focused in the same way as Lenses. This library re-exports Effect's `Subscribable` module and adds value and error transforms, plus recovery (`catchAll`, `catchAllCause`, `orElse`, `orElseSucceed`, and `retry`):
```typescript
import { Subscribable } from "effect-lens"