@vladkrutenyuk/three-kvy-core
Version:
Everything you need to create any-complexity 3D apps with Three.js. Empower Three.js with a modular, lifecycle-managed context that seamlessly propagates through objects via reusable features providing structured logic.
38 lines (37 loc) • 2.24 kB
TypeScript
import { EventEmitter } from "eventemitter3";
import { CoreContext, ModulesRecord, ModulesRecordDefault } from "./CoreContext";
/**
* Base class, acting as a pluggable module, for extending {@link CoreContext} functionality.\
* It enables clean separation of concerns while maintaining full access to context capabilities.\
* Modules are assigned to context {@link CoreContext}, can provide services to features {@link Object3DFeature}, and manage their own
* lifecycle through the {@link useCtx useCtx(ctx)} pattern.
* @see {@link https://three-kvy-core.vladkrutenyuk.ru/docs/api/core-context-module | Official Documentation}
* @see {@link https://github.com/vladkrutenyuk/three-kvy-core/blob/main/src/core/CoreContextModule.ts | Source}
*/
export declare abstract class CoreContextModule<TEventTypes extends EventEmitter.ValidEventTypes = string | symbol, TModules extends ModulesRecord = ModulesRecordDefault> extends EventEmitter<TEventTypes> {
/** Read-only flag to mark that it is an instance of {@link CoreContextModule}.*/
readonly isCoreContextModule: true;
/**
* (readonly) Getter for the instance of {@link CoreContext} this is assigned to.
* @warning **Throws exception** if try to access before assign.
*/
get ctx(): CoreContext<TModules>;
/** (readonly) Flag to check if this instance has been assigned to some {@link CoreContext}. */
get hasCtx(): boolean;
private _ctx?;
constructor();
/**
* Overridable Lifecycle Method. Called when the module is assigned to a {@link CoreContext}. \
* The returned cleanup function (optional) is called when the module is removed from the context.\
* Also cleanup is called if context is destroyed.\
* Calling the method manually is prohibited.
* @param {CoreContext} ctx - An instance of {@link CoreContext} to which this module was assigned.
* @returns {Function | undefined}
*/
protected useCtx(ctx: CoreContext<TModules>): ReturnOfUseCtx;
}
export type ReturnOfUseCtx = undefined | (() => void) | void;
export interface ICoreContextModuleProtected {
_ctx?: CoreContext<ModulesRecordDefault>;
useCtx<TModules extends ModulesRecord>(ctx: CoreContext<TModules>): ReturnOfUseCtx;
}