Fix
All checks were successful
Lint / lint (push) Successful in 13s
Test build / test-build (pull_request) Successful in 15s

This commit is contained in:
Julien Valverdé
2026-04-30 01:41:46 +02:00
parent 6469185984
commit f1ab8a1af2
2 changed files with 9 additions and 13 deletions

View File

@@ -36,13 +36,13 @@ Lens<
### Creating a Lens
#### From an exisiting type
#### From an existing type
We provide a few helpers to create Lenses from some Effect types:
```typescript
// The ref is the data source
const ref = yield* SubscriptionRef.make([12, 87, 69])
// The lens acts as a proxy that allows reading, subscribing from and writing to that
// The lens acts as a proxy that allows reading, subscribing to and writing to that
// data source with a similar API to Effect's SubscriptionRef
const lens = Lens.fromSubscriptionRef(ref)
// ^ Lens.Lens<number[], never, never, never, never>
@@ -54,7 +54,7 @@ yield* Lens.update(lens, Array.replace(1, 1664))
Currently available:
- `fromSubscriptionRef`
- `fromSynchronizedRef` (note: since `SynchronizedRef` is not reactive (does not produces a stream of value changes), the resulting Lens' `changes` stream will only emit the current value of the lens when evaluated, and nothing else)
- `fromSynchronizedRef` (note: since `SynchronizedRef` is not reactive (does not produce a stream of value changes), the resulting Lens' `changes` stream will only emit the current value of the lens when evaluated, and nothing else)
More to come!
@@ -110,7 +110,7 @@ Lens<{ readonly a: string, readonly b: number }, never, never, never, never>
Lens<string, never, never, never, never>
```
Focuses Lenses work just the same as a Lens that points directly to a data source and can be read, subscribed to or written to.
Focused Lenses work just the same as a Lens that points directly to a data source and can be read, subscribed to or written to.
Writing to them will properly update parent Lenses or data sources. Such updates can be performed in both a mutable or an immutable manner depending on your choice.
@@ -141,7 +141,7 @@ const jeanDupontLens = ref.pipe(
Lens.focusObjectOn("users"), // Creates a focused lens that points to the users field
Lens.focusArrayAt(0), // Creates a focused lens that points to the first entry of the user array
)
// Reading or writing from this lense can fail with NoSuchElementException
// Reading or writing from this lens can fail with NoSuchElementException
// This is because of Lens.focusArrayAt(0), as reading and writing to an array is an unsafe operation
const jeanDupont = yield* Lens.get(jeanDupontLens)
@@ -211,7 +211,7 @@ const someFunctionThatShouldOnlyHaveReadonlyAccessToTheState = (
// Do whatever
const usersCountSub = Subscribable.map(usersSub, a => a.length)
const users = yield* usersSub.get
yield* Effect.forkScoped(Stream.runForEach(users.changes, ...))
yield* Effect.forkScoped(Stream.runForEach(usersSub.changes, ...))
})
const lens = ref.pipe(
@@ -226,9 +226,9 @@ This library re-exports Effect's `Subscribable` module and adds a few transforms
```typescript
import { Subscribable } from "effect-lens"
declare const sub: Subscribabe.Subscribable<readonly { name: string }[], never, never>
declare const sub: Subscribable.Subscribable<readonly { name: string }[], never, never>
// \/ Subscribabe.Subscribable<string, NoSuchElementException, never>
// \/ Subscribable.Subscribable<string, NoSuchElementException, never>
const nameSub = sub.pipe(
Subscribable.focusArrayAt(1),
Subscribable.focusObjectOn("name"),

View File

@@ -1,7 +1,7 @@
{
"name": "effect-lens",
"description": "An effectful Lens type to easily manage nested state",
"version": "0.1.4",
"version": "0.1.5",
"type": "module",
"files": [
"./README.md",
@@ -21,10 +21,6 @@
"types": "./dist/Lens.d.ts",
"default": "./dist/Lens.js"
},
"./PropertyPath": {
"types": "./dist/PropertyPath.d.ts",
"default": "./dist/PropertyPath.js"
},
"./Subscribable": {
"types": "./dist/Subscribable.d.ts",
"default": "./dist/Subscribable.js"