0.2.0 #18

Merged
Thilawyn merged 44 commits from next into master 2025-10-24 01:36:27 +02:00
2 changed files with 14 additions and 10 deletions
Showing only changes of commit c03d697361 - Show all commits

View File

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

View File

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