@@ -613,25 +613,15 @@ export const useCallbackPromise: {
|
|||||||
})
|
})
|
||||||
|
|
||||||
export namespace useContext {
|
export namespace useContext {
|
||||||
export type Options = useScope.Options
|
export type Options = useOnChange.Options
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useContext: {
|
export const useContext = <ROut, E, RIn>(
|
||||||
<ROut, E, RIn>(
|
|
||||||
layer: Layer.Layer<ROut, E, RIn>,
|
layer: Layer.Layer<ROut, E, RIn>,
|
||||||
options?: useContext.Options,
|
options?: useContext.Options,
|
||||||
): Effect.Effect<Context.Context<ROut>, E, RIn>
|
): Effect.Effect<Context.Context<ROut>, E, RIn> => useOnChange(() => Effect.context<RIn>().pipe(
|
||||||
} = Effect.fnUntraced(function* <ROut, E, RIn>(
|
|
||||||
layer: Layer.Layer<ROut, E, RIn>,
|
|
||||||
options?: useContext.Options,
|
|
||||||
) {
|
|
||||||
const scope = yield* useScope([layer], options)
|
|
||||||
|
|
||||||
return yield* useOnChange(() => Effect.context<RIn>().pipe(
|
|
||||||
Effect.map(context => ManagedRuntime.make(Layer.provide(layer, Layer.succeedContext(context)))),
|
Effect.map(context => ManagedRuntime.make(Layer.provide(layer, Layer.succeedContext(context)))),
|
||||||
Effect.tap(runtime => Effect.addFinalizer(() => runtime.disposeEffect)),
|
Effect.tap(runtime => Effect.addFinalizer(() => runtime.disposeEffect)),
|
||||||
Effect.andThen(runtime => runtime.runtimeEffect),
|
Effect.andThen(runtime => runtime.runtimeEffect),
|
||||||
Effect.andThen(runtime => runtime.context),
|
Effect.andThen(runtime => runtime.context),
|
||||||
Effect.provideService(Scope.Scope, scope),
|
), [layer], options)
|
||||||
), [scope])
|
|
||||||
})
|
|
||||||
|
|||||||
Reference in New Issue
Block a user