0.1.5 #4

Merged
Thilawyn merged 4 commits from next into master 2026-04-30 01:55:49 +02:00
2 changed files with 9 additions and 13 deletions
Showing only changes of commit f1ab8a1af2 - Show all commits

View File

@@ -36,13 +36,13 @@ Lens<
### Creating a Lens ### Creating a Lens
#### From an exisiting type #### From an existing type
We provide a few helpers to create Lenses from some Effect types: We provide a few helpers to create Lenses from some Effect types:
```typescript ```typescript
// The ref is the data source // The ref is the data source
const ref = yield* SubscriptionRef.make([12, 87, 69]) 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 // data source with a similar API to Effect's SubscriptionRef
const lens = Lens.fromSubscriptionRef(ref) const lens = Lens.fromSubscriptionRef(ref)
// ^ Lens.Lens<number[], never, never, never, never> // ^ Lens.Lens<number[], never, never, never, never>
@@ -54,7 +54,7 @@ yield* Lens.update(lens, Array.replace(1, 1664))
Currently available: Currently available:
- `fromSubscriptionRef` - `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! More to come!
@@ -110,7 +110,7 @@ Lens<{ readonly a: string, readonly b: number }, never, never, never, never>
Lens<string, 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. 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.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 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 // This is because of Lens.focusArrayAt(0), as reading and writing to an array is an unsafe operation
const jeanDupont = yield* Lens.get(jeanDupontLens) const jeanDupont = yield* Lens.get(jeanDupontLens)
@@ -211,7 +211,7 @@ const someFunctionThatShouldOnlyHaveReadonlyAccessToTheState = (
// Do whatever // Do whatever
const usersCountSub = Subscribable.map(usersSub, a => a.length) const usersCountSub = Subscribable.map(usersSub, a => a.length)
const users = yield* usersSub.get const users = yield* usersSub.get
yield* Effect.forkScoped(Stream.runForEach(users.changes, ...)) yield* Effect.forkScoped(Stream.runForEach(usersSub.changes, ...))
}) })
const lens = ref.pipe( const lens = ref.pipe(
@@ -226,9 +226,9 @@ This library re-exports Effect's `Subscribable` module and adds a few transforms
```typescript ```typescript
import { Subscribable } from "effect-lens" 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( const nameSub = sub.pipe(
Subscribable.focusArrayAt(1), Subscribable.focusArrayAt(1),
Subscribable.focusObjectOn("name"), Subscribable.focusObjectOn("name"),

View File

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