0.2.1 #26

Merged
Thilawyn merged 144 commits from next into master 2025-12-01 23:37:40 +01:00
Showing only changes of commit 2094f254b3 - Show all commits

View File

@@ -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>,
options?: useContext.Options,
): Effect.Effect<Context.Context<ROut>, E, RIn>
} = Effect.fnUntraced(function* <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> => useOnChange(() => Effect.context<RIn>().pipe(
const scope = yield* useScope([layer], options) Effect.map(context => ManagedRuntime.make(Layer.provide(layer, Layer.succeedContext(context)))),
Effect.tap(runtime => Effect.addFinalizer(() => runtime.disposeEffect)),
return yield* useOnChange(() => Effect.context<RIn>().pipe( Effect.andThen(runtime => runtime.runtimeEffect),
Effect.map(context => ManagedRuntime.make(Layer.provide(layer, Layer.succeedContext(context)))), Effect.andThen(runtime => runtime.context),
Effect.tap(runtime => Effect.addFinalizer(() => runtime.disposeEffect)), ), [layer], options)
Effect.andThen(runtime => runtime.runtimeEffect),
Effect.andThen(runtime => runtime.context),
Effect.provideService(Scope.Scope, scope),
), [scope])
})