0.2.1 #26
@@ -31,16 +31,17 @@ export const useSubscriptionRefState: {
|
|||||||
export const useSubscriptionRefFromState: {
|
export const useSubscriptionRefFromState: {
|
||||||
<A>(state: readonly [A, React.Dispatch<React.SetStateAction<A>>]): Effect.Effect<SubscriptionRef.SubscriptionRef<A>, never, Scope.Scope>
|
<A>(state: readonly [A, React.Dispatch<React.SetStateAction<A>>]): Effect.Effect<SubscriptionRef.SubscriptionRef<A>, never, Scope.Scope>
|
||||||
} = Effect.fnUntraced(function*([value, setValue]) {
|
} = Effect.fnUntraced(function*([value, setValue]) {
|
||||||
const ref = yield* Component.useOnMount(() => SubscriptionRef.make(value))
|
const ref = yield* Component.useOnChange(() => Effect.tap(
|
||||||
|
SubscriptionRef.make(value),
|
||||||
yield* Component.useReactEffect(() => Effect.forkScoped(
|
ref => Effect.forkScoped(
|
||||||
Stream.runForEach(
|
Stream.runForEach(
|
||||||
Stream.changesWith(ref.changes, Equivalence.strict()),
|
Stream.changesWith(ref.changes, Equivalence.strict()),
|
||||||
v => Effect.sync(() => setValue(v)),
|
v => Effect.sync(() => setValue(v)),
|
||||||
)
|
)
|
||||||
|
),
|
||||||
), [setValue])
|
), [setValue])
|
||||||
yield* Component.useReactEffect(() => Ref.set(ref, value), [value])
|
|
||||||
|
|
||||||
|
yield* Component.useReactEffect(() => Ref.set(ref, value), [value])
|
||||||
return ref
|
return ref
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user