Co-authored-by: Julien Valverdé <julien.valverde@mailo.com> Co-authored-by: Renovate Bot <renovate-bot@valverde.cloud> Reviewed-on: #26
15 lines
617 B
TypeScript
15 lines
617 B
TypeScript
import { Effect, PubSub, type Scope } from "effect"
|
|
import type * as React from "react"
|
|
import * as Component from "./Component.js"
|
|
|
|
|
|
export const usePubSubFromReactiveValues = Effect.fnUntraced(function* <const A extends React.DependencyList>(
|
|
values: A
|
|
): Effect.fn.Return<PubSub.PubSub<A>, never, Scope.Scope> {
|
|
const pubsub = yield* Component.useOnMount(() => Effect.acquireRelease(PubSub.unbounded<A>(), PubSub.shutdown))
|
|
yield* Component.useReactEffect(() => Effect.unlessEffect(PubSub.publish(pubsub, values), PubSub.isShutdown(pubsub)), values)
|
|
return pubsub
|
|
})
|
|
|
|
export * from "effect/PubSub"
|