Fix
All checks were successful
Lint / lint (push) Successful in 11s

This commit is contained in:
Julien Valverdé
2025-07-06 03:35:43 +02:00
parent 0060bb792a
commit 7ff331b062
2 changed files with 11 additions and 5 deletions

View File

@@ -1,4 +1,4 @@
import { Effect, Effectable, Option, Readable, Ref, Stream, Subscribable, SubscriptionRef, SynchronizedRef, type Types, type Unify } from "effect" import { Chunk, Effect, Effectable, Option, Readable, Ref, Stream, Subscribable, SubscriptionRef, SynchronizedRef, type Types, type Unify } from "effect"
import * as PropertyPath from "./PropertyPath.js" import * as PropertyPath from "./PropertyPath.js"
@@ -100,3 +100,12 @@ export const makeFromPath = <B, const P extends PropertyPath.Paths<B>>(
parentValue => Option.getOrThrow(PropertyPath.get(parentValue, path)), parentValue => Option.getOrThrow(PropertyPath.get(parentValue, path)),
(parentValue, value) => Option.getOrThrow(PropertyPath.immutableSet(parentValue, path, value)), (parentValue, value) => Option.getOrThrow(PropertyPath.immutableSet(parentValue, path, value)),
) )
export const makeFromChunkRef = <A>(
parent: SubscriptionRef.SubscriptionRef<Chunk.Chunk<A>>,
index: number,
): SubscriptionSubRef<A, Chunk.Chunk<A>> => new SubscriptionSubRefImpl(
parent,
parentValue => Chunk.unsafeGet(parentValue, index),
(parentValue, value) => Chunk.replace(parentValue, index, value),
)

View File

@@ -37,10 +37,7 @@ export const Todo = Component.make(function* Todo(props: TodoProps) {
const ref = yield* Hook.useMemo(() => Match.value(props).pipe( const ref = yield* Hook.useMemo(() => Match.value(props).pipe(
Match.tag("new", () => Effect.andThen(makeTodo, SubscriptionRef.make)), Match.tag("new", () => Effect.andThen(makeTodo, SubscriptionRef.make)),
Match.tag("edit", ({ index }) => Effect.succeed(SubscriptionSubRef.makeFromGetSet(state.ref, { Match.tag("edit", ({ index }) => Effect.succeed(SubscriptionSubRef.makeFromChunkRef(state.ref, index))),
get: parent => Chunk.unsafeGet(parent, index),
set: (parent, v) => Chunk.replace(parent, index, v),
}))),
Match.exhaustive, Match.exhaustive,
), [props._tag, props.index]) ), [props._tag, props.index])