0.2.1 #26
@@ -405,15 +405,15 @@ export const withRuntime: {
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
export class ComponentScopeMap extends Effect.Service<ComponentScopeMap>()("effect-fc/Component/ComponentScopeMap", {
|
export class ScopeMap extends Effect.Service<ScopeMap>()("effect-fc/Component/ScopeMap", {
|
||||||
effect: Effect.bind(
|
effect: Effect.bind(
|
||||||
Effect.Do,
|
Effect.Do,
|
||||||
"ref",
|
"ref",
|
||||||
() => Ref.make(HashMap.empty<string, ComponentScopeMap.Entry>()),
|
() => Ref.make(HashMap.empty<string, ScopeMap.Entry>()),
|
||||||
),
|
),
|
||||||
}) {}
|
}) {}
|
||||||
|
|
||||||
export namespace ComponentScopeMap {
|
export namespace ScopeMap {
|
||||||
export interface Entry {
|
export interface Entry {
|
||||||
readonly scope: Scope.CloseableScope
|
readonly scope: Scope.CloseableScope
|
||||||
readonly closeFiber: Option.Option<Fiber.RuntimeFiber<void>>
|
readonly closeFiber: Option.Option<Fiber.RuntimeFiber<void>>
|
||||||
@@ -432,7 +432,7 @@ export const useScope: {
|
|||||||
runtimeRef.current = yield* Effect.runtime()
|
runtimeRef.current = yield* Effect.runtime()
|
||||||
|
|
||||||
const key = React.useId()
|
const key = React.useId()
|
||||||
const scopeMap = yield* ComponentScopeMap as unknown as Effect.Effect<ComponentScopeMap>
|
const scopeMap = yield* ScopeMap as unknown as Effect.Effect<ScopeMap>
|
||||||
|
|
||||||
const scope = React.useMemo(() => Runtime.runSync(runtimeRef.current)(Effect.andThen(
|
const scope = React.useMemo(() => Runtime.runSync(runtimeRef.current)(Effect.andThen(
|
||||||
scopeMap.ref,
|
scopeMap.ref,
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ export const isReactRuntime = (u: unknown): u is ReactRuntime<unknown, unknown>
|
|||||||
export const make = <R, ER>(
|
export const make = <R, ER>(
|
||||||
layer: Layer.Layer<R, ER>,
|
layer: Layer.Layer<R, ER>,
|
||||||
memoMap?: Layer.MemoMap,
|
memoMap?: Layer.MemoMap,
|
||||||
): ReactRuntime<R | Component.ComponentScopeMap, ER> => Object.setPrototypeOf(
|
): ReactRuntime<R | Component.ScopeMap, ER> => Object.setPrototypeOf(
|
||||||
Object.assign(function() {}, {
|
Object.assign(function() {}, {
|
||||||
runtime: ManagedRuntime.make(
|
runtime: ManagedRuntime.make(
|
||||||
Layer.merge(layer, Component.ComponentScopeMap.Default),
|
Layer.merge(layer, Component.ScopeMap.Default),
|
||||||
memoMap,
|
memoMap,
|
||||||
),
|
),
|
||||||
// biome-ignore lint/style/noNonNullAssertion: context initialization
|
// biome-ignore lint/style/noNonNullAssertion: context initialization
|
||||||
|
|||||||
Reference in New Issue
Block a user