Rename Subscribable to View in next
Lint / lint (push) Successful in 25s

This commit is contained in:
Julien Valverdé
2026-07-16 20:56:55 +02:00
parent fd0e84f136
commit 5c7687458a
7 changed files with 287 additions and 287 deletions
+13 -13
View File
@@ -240,21 +240,21 @@ const nameLens = lens.pipe(
```
### Subscribable
### View
Effect 4 no longer provides `Subscribable` and `Readable`. This library provides its own `Subscribable` interface, 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 4 no longer provides its former `Subscribable` and `Readable` abstractions. This library provides a `View` interface, 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:
```typescript
const ref = yield* SubscriptionRef.make<{
readonly users: readonly User[]
}>({ users: [...] })
const someFunctionThatShouldOnlyHaveReadonlyAccessToTheState = (
usersSub: Subscribable.Subscribable<readonly User[], never, never>
usersView: View.View<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 usersCountView = View.map(usersView, a => a.length)
const users = yield* usersView.get
yield* Effect.forkScoped(Stream.runForEach(usersView.changes, ...))
})
const lens = ref.pipe(
@@ -265,16 +265,16 @@ yield* someFunctionThatShouldOnlyHaveReadonlyAccessToTheState(lens)
```
#### Focusing
This library provides a `Subscribable` module with value and error transforms, recovery (`catch`, `catchCause`, `orElse`, `orElseSucceed`, and `retry`), and transforms to narrow the focus of `Subscribable`'s, same as Lenses:
This library provides a `View` module with value and error transforms, recovery (`catch`, `catchCause`, `orElse`, `orElseSucceed`, and `retry`), and transforms to narrow the focus of `View`'s, same as Lenses:
```typescript
import { Subscribable } from "effect-lens"
import { View } from "effect-lens"
declare const sub: Subscribable.Subscribable<readonly { name: string }[], never, never>
declare const view: View.View<readonly { name: string }[], never, never>
// \/ Subscribable.Subscribable<string, NoSuchElementError, never>
const nameSub = sub.pipe(
Subscribable.focusArrayAt(1),
Subscribable.focusObjectOn("name"),
// \/ View.View<string, NoSuchElementError, never>
const nameView = view.pipe(
View.focusArrayAt(1),
View.focusObjectOn("name"),
)
```