@studiometa/js-toolkit
Version:
A set of useful little bits of JavaScript to boost your project! 🚀
77 lines (76 loc) • 2.69 kB
TypeScript
import type { Base, BaseConstructor, BaseAsyncConstructor, BaseEl } from '../index.js';
import { AbstractManager } from './AbstractManager.js';
/**
* Children manager.
*/
export declare class ChildrenManager<T> extends AbstractManager<T> {
/**
* Store async component promises to avoid calling them multiple times and
* waiting for them when they are already resolved.
*/
__asyncComponentPromises: WeakMap<BaseAsyncConstructor, {
promise: ReturnType<BaseAsyncConstructor>;
status: 'pending' | 'resolved';
ctor?: BaseConstructor;
}>;
get registeredNames(): string[];
/**
* Register instances of all children components.
*/
registerAll(): Promise<void>;
/**
* Mount all child component instances.
*/
mountAll(): Promise<void>;
/**
* Update all child component instances.
*/
updateAll(): Promise<void>;
/**
* Destroy all child component instances.
*/
destroyAll(): Promise<void>;
/**
* Execute the given hook for the given instance.
*
* @param {'$mount'|'$update'|'$destroy'} hook The hook to trigger.
* @param {Base} instance The target instance.
* @param {string} name The name of the component.
* @private
*/
__triggerHook(hook: '$mount' | '$update' | '$destroy', instance: Base, name: string): Promise<void>;
/**
* Register instance of a child component.
*
* @param {string} name
* The name of the child component.
* @param {BaseConstructor|BaseAsyncConstructor} component
* A Base class or a Promise for async components.
* @private
*/
__register(name: string, component: BaseConstructor | BaseAsyncConstructor): void;
/**
* Get children.
* @private
*/
__getValue(name: string, component: BaseConstructor | BaseAsyncConstructor): any[];
/**
* Get a child component's instance.
*
* @param {BaseEl} el
* The root element of the child component.
* @param {BaseConstructor|BaseAsyncConstructor} ComponentClass
* A Base class or a Promise for async components.
* @return {Base|Promise<Base | 'terminated'>|'terminated'}
* A Base instance or a Promise resolving to a Base instance.
* @private
*/
__getChild(el: BaseEl, ComponentClass: BaseConstructor | BaseAsyncConstructor): Base | Promise<Base | 'terminated'> | 'terminated';
/**
* Execute the given hook for all children instances.
*
* @param {'$mount'|'$update'|'$destroy'} hook The hook to execute.
* @private
*/
__triggerHookForAll(hook: '$mount' | '$update' | '$destroy'): Promise<unknown>;
}