@@ -0,0 +1,26 @@
|
||||
import { Context, Effect, type Fiber, HashMap, Layer, type Option, Ref, type Scope } from "effect"
|
||||
|
||||
|
||||
/**
|
||||
* Internal Effect service that maintains a registry of scopes associated with React component instances.
|
||||
*
|
||||
* This service is used internally by the `Component.useScope` hook to manage the lifecycle of component scopes,
|
||||
* including tracking active scopes and coordinating their cleanup when components unmount or dependencies change.
|
||||
*/
|
||||
export class ScopeRegistry extends Context.Service<ScopeRegistry, {
|
||||
readonly ref: Ref.Ref<HashMap.HashMap<object, ScopeRegistry.Entry>>
|
||||
}>()(
|
||||
"@effect-fc/ScopeRegistry/ScopeRegistry"
|
||||
) {
|
||||
static readonly layer = Layer.effect(ScopeRegistry, Effect.map(
|
||||
Ref.make(HashMap.empty<object, ScopeRegistry.Entry>()),
|
||||
ref => ({ ref }),
|
||||
))
|
||||
}
|
||||
|
||||
export declare namespace ScopeRegistry {
|
||||
export interface Entry {
|
||||
readonly scope: Scope.Closeable
|
||||
readonly closeFiber: Option.Option<Fiber.Fiber<void>>
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user