@@ -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),
|
||||||
|
)
|
||||||
|
|||||||
@@ -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])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user