UNPKG

@studiometa/js-toolkit

Version:

A set of useful little bits of JavaScript to boost your project! 🚀

82 lines (81 loc) • 2.63 kB
import { usePointer, useRaf, useResize, useScroll, useKey } from '../../services/index.js'; import type { PointerServiceInterface, RafServiceInterface, ResizeServiceInterface, ScrollServiceInterface, KeyServiceInterface, ServiceInterface } from '../../services/index.js'; import { AbstractManager } from './AbstractManager.js'; declare const SERVICES_MAP: { scrolled: typeof useScroll; resized: typeof useResize; ticked: typeof useRaf; moved: typeof usePointer; keyed: typeof useKey; }; type Services = { scrolled: ScrollServiceInterface; resized: ResizeServiceInterface; ticked: RafServiceInterface; moved: PointerServiceInterface; keyed: KeyServiceInterface; } & Record<string, ServiceInterface<unknown>>; type ServiceProps = typeof SERVICES_MAP & Record<string, <T>() => ServiceInterface<T>>; type ServiceNames = keyof Services; /** * Services management for the Base class. * * @todo Add support for disabled services on mount when the method is defined. */ export declare class ServicesManager extends AbstractManager<ServiceProps> { /** * Custom props * @private */ __props: ServiceProps; /** * Test if the given service is registered. */ has(service: ServiceNames | string): boolean; /** * Get a service props by name. */ get<S extends ServiceNames | string>(service: S): ReturnType<Services[S]['props']>; /** * Init the given service and bind it to the given instance. * * @param {ServiceNames} service The name of the service. * @return {() => void} A function to unbind the service. */ enable(service: ServiceNames): () => void; /** * Enable all services and return methods to disable them. */ enableAll(): (() => void)[]; /** * Disable all services. * * @return {void} */ disableAll(): void; /** * Disable a service. */ disable(service: ServiceNames): void; /** * Toggle a service. */ toggle(service: ServiceNames, force?: boolean): void; /** * Register a new service to be enabled/disabled. * * @param {string} name * The name of the service hook. * @param {<T>(...args:unknown[]) => ServiceInterface<T>} useFunction * The `use...` function for the service. */ register(name: string, useFunction: <T>(...args: unknown[]) => ServiceInterface<T>): void; /** * Unregister a new service to be enabled disabled. * * @param {string} name * The name of the service hook. */ unregister(name: string): void; } export {};