UNPKG

solid-services

Version:

Solid.js library adding a services layer for global shared state.

59 lines (58 loc) 2.17 kB
export declare class Service { } type ServiceFunction<T extends Service> = () => T; type ServiceConstructor<T extends Service> = new () => T; export type ServiceInitializer<T extends Service> = ServiceFunction<T> | ServiceConstructor<T>; export interface RegistryConfig { expose?: ServiceInitializer<any>[] | boolean; } /** * Registry is a container for services. * It is used to register and retrieve services. */ export declare class Registry { #private; constructor(config?: RegistryConfig); /** * Checks weather the registry has a service registered for the given initializer. * * First it will check in the parent registry and if no service is registered there, * it will check in the current registry. */ has<T extends Service>(initializer: ServiceInitializer<T>): boolean; /** * Returns the service registered for the given initializer. * * First it will try to find it in the parent registry and if no service is registered there, * it will check in the current registry. */ get<T extends Service>(initializer: ServiceInitializer<T>): T | undefined; /** * Clears the registry. */ clear(): void; /** * Deletes registered service for the given initializer. */ delete<T extends Service>(initializer: ServiceInitializer<T>): void; /** * Registers a service for the given initializer. * * If the registry has a parent registry, it will check if the service is exposed there. * * If it is exposed, it will register the service in the parent registry. * * If it is not exposed, it will register the service in the current registry. * * If the registry does not have a parent registry, it will register the service in the current registry. */ register<T extends Service>(initializer: ServiceInitializer<T>): T; protected isExposing<T extends Service>(initializer: ServiceInitializer<T>): boolean; private getParentRegistry; private initializeService; } /** * Creates a new registry for services. */ export declare function createRegistry(config?: RegistryConfig): Registry; export {};