From 7ff331b06215d7ef7066f2d0f9c8ddcbf586220e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Sun, 6 Jul 2025 03:35:43 +0200 Subject: [PATCH] Fix --- packages/effect-fc/src/types/SubscriptionSubRef.ts | 11 ++++++++++- packages/example/src/todo/Todo.tsx | 5 +---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/effect-fc/src/types/SubscriptionSubRef.ts b/packages/effect-fc/src/types/SubscriptionSubRef.ts index 0f2db0d..579362a 100644 --- a/packages/effect-fc/src/types/SubscriptionSubRef.ts +++ b/packages/effect-fc/src/types/SubscriptionSubRef.ts @@ -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" @@ -100,3 +100,12 @@ export const makeFromPath = >( parentValue => Option.getOrThrow(PropertyPath.get(parentValue, path)), (parentValue, value) => Option.getOrThrow(PropertyPath.immutableSet(parentValue, path, value)), ) + +export const makeFromChunkRef = ( + parent: SubscriptionRef.SubscriptionRef>, + index: number, +): SubscriptionSubRef> => new SubscriptionSubRefImpl( + parent, + parentValue => Chunk.unsafeGet(parentValue, index), + (parentValue, value) => Chunk.replace(parentValue, index, value), +) diff --git a/packages/example/src/todo/Todo.tsx b/packages/example/src/todo/Todo.tsx index 13a6872..0b78b4d 100644 --- a/packages/example/src/todo/Todo.tsx +++ b/packages/example/src/todo/Todo.tsx @@ -37,10 +37,7 @@ export const Todo = Component.make(function* Todo(props: TodoProps) { const ref = yield* Hook.useMemo(() => Match.value(props).pipe( Match.tag("new", () => Effect.andThen(makeTodo, SubscriptionRef.make)), - Match.tag("edit", ({ index }) => Effect.succeed(SubscriptionSubRef.makeFromGetSet(state.ref, { - get: parent => Chunk.unsafeGet(parent, index), - set: (parent, v) => Chunk.replace(parent, index, v), - }))), + Match.tag("edit", ({ index }) => Effect.succeed(SubscriptionSubRef.makeFromChunkRef(state.ref, index))), Match.exhaustive, ), [props._tag, props.index])