|
|
|
@@ -1,4 +1,3 @@
|
|
|
|
|
import * as AsyncData from "@typed/async-data"
|
|
|
|
|
import { type Context, Effect, Equivalence, ExecutionStrategy, Exit, type Layer, Option, pipe, PubSub, Ref, Runtime, Scope, Stream, SubscriptionRef } from "effect"
|
|
|
|
|
import * as React from "react"
|
|
|
|
|
import { SetStateAction } from "./types/index.js"
|
|
|
|
@@ -197,29 +196,6 @@ export const useContext: {
|
|
|
|
|
), [scope])
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const useContextAsync: {
|
|
|
|
|
<ROut, E, RIn>(
|
|
|
|
|
layer: Layer.Layer<ROut, E, RIn>,
|
|
|
|
|
options?: ScopeOptions,
|
|
|
|
|
): Effect.Effect<AsyncData.AsyncData<Context.Context<ROut>, E>, never, Exclude<RIn, Scope.Scope>>
|
|
|
|
|
} = Effect.fn("useContextAsync")(function* <ROut, E, RIn>(
|
|
|
|
|
layer: Layer.Layer<ROut, E, RIn>,
|
|
|
|
|
options?: ScopeOptions,
|
|
|
|
|
) {
|
|
|
|
|
const [context, setContext] = React.useState<AsyncData.AsyncData<Context.Context<ROut>, E>>(AsyncData.noData())
|
|
|
|
|
|
|
|
|
|
yield* useFork(() => Effect.sync(() => setContext(AsyncData.loading())).pipe(
|
|
|
|
|
Effect.andThen(Effect.provide(Effect.context<ROut>(), layer)),
|
|
|
|
|
Effect.match({
|
|
|
|
|
onSuccess: v => AsyncData.success(v),
|
|
|
|
|
onFailure: e => AsyncData.fail(e),
|
|
|
|
|
}),
|
|
|
|
|
Effect.andThen(setContext),
|
|
|
|
|
), [layer], options)
|
|
|
|
|
|
|
|
|
|
return context
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const useRefFromReactiveValue: {
|
|
|
|
|
<A>(value: A): Effect.Effect<SubscriptionRef.SubscriptionRef<A>>
|
|
|
|
|