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

This commit is contained in:
Julien Valverdé
2025-10-23 16:20:30 +02:00
parent 3847686d54
commit c03d697361
2 changed files with 14 additions and 10 deletions

View File

@@ -33,13 +33,13 @@ export const useSubscribables: {
yield* Component.useOnMount(() => Effect.all(elements.map(v => v.get)))
)
yield* Component.useOnChange(() => Effect.forkScoped(pipe(
yield* Component.useReactEffect(() => Effect.forkScoped(pipe(
elements.map(ref => Stream.changesWith(ref.changes, Equivalence.strict())),
streams => Stream.zipLatestAll(...streams),
Stream.runForEach(v =>
Effect.sync(() => setReactStateValue(v))
),
)), elements)
)), elements, { finalizerExecutionMode: "fork" })
return reactStateValue as any
})

View File

@@ -11,10 +11,12 @@ export const useSubscriptionRefState: {
} = Effect.fnUntraced(function* <A>(ref: SubscriptionRef.SubscriptionRef<A>) {
const [reactStateValue, setReactStateValue] = React.useState(yield* Component.useOnMount(() => ref))
yield* Component.useOnChange(() => Effect.forkScoped(Stream.runForEach(
Stream.changesWith(ref.changes, Equivalence.strict()),
v => Effect.sync(() => setReactStateValue(v)),
)), [ref])
yield* Component.useReactEffect(() => Effect.forkScoped(
Stream.runForEach(
Stream.changesWith(ref.changes, Equivalence.strict()),
v => Effect.sync(() => setReactStateValue(v)),
)
), [ref], { finalizerExecutionMode: "fork" })
const setValue = yield* Component.useCallbackSync((setStateAction: React.SetStateAction<A>) =>
Effect.andThen(
@@ -31,10 +33,12 @@ export const useSubscriptionRefFromState: {
} = Effect.fnUntraced(function*([value, setValue]) {
const ref = yield* Component.useOnMount(() => SubscriptionRef.make(value))
yield* Component.useOnChange(() => Effect.forkScoped(Stream.runForEach(
Stream.changesWith(ref.changes, Equivalence.strict()),
v => Effect.sync(() => setValue(v)),
)), [setValue])
yield* Component.useReactEffect(() => Effect.forkScoped(
Stream.runForEach(
Stream.changesWith(ref.changes, Equivalence.strict()),
v => Effect.sync(() => setValue(v)),
)
), [setValue], { finalizerExecutionMode: "fork" })
yield* Component.useReactEffect(() => Ref.set(ref, value), [value])
return ref