import { ConstructorForComponent } from './component'; import { ContextManager } from './context'; import { Event } from './event'; import { Observable } from './observable'; import { ZComponent } from './zcomponent'; /** * Base class for all components and behaviors. */ export declare class Entity { readonly contextManager: ContextManager; private _registered; private _handlersBound; private _zcomponent; private _disposed; /** * An event that is fired as the last act of this entity being destroyed. */ readonly onDispose: Event<[]>; /** * Creates an instance of Entity. * @param contextManager The current ContextManager */ constructor(contextManager: ContextManager); /** * Gets the disposed status of the entity. * @returns {boolean} The disposed status. */ get disposed(): boolean; /** * Sets the disposed status of the entity. * @param {boolean} v - The new disposed status. * @private */ private set disposed(value); /** * If `false`, this entity and its children will no longer participate in the experience. * * Note - to read this value, you may wish to use `enabledResolved` which will be `false` if * this entity, or any of its parents, have `enabled` set to false. * * The precise implications of `enabled` being false will vary between entities, * but in general disabled entities: * - should not emit any events, * - should not take any action, e.g. navigate the user to a different page, * - should not perform any network communication, * - should not make changes to other behaviors or components in the experience, * - should minimise any runtime performance cost (e.g. detach from any frame handlers). * * @zprop * @zdefault true * @zgroup Behavior * @zgrouppriority 10 */ readonly enabled: Observable; /** * This will have value `false` if this entity, or any of its parents, have `enabled` set to `false`. * * To change the `enabled` status of this entity, use the `enabled` property instead. * * The precise implications of `enabled` being false will vary between entities, * but in general disabled entities: * - should not emit any events, * - should not take any action, e.g. navigate the user to a different page, * - should not perform any network communication, * - should not make changes to other behaviors or components in the experience, * - should minimise any runtime performance cost. * * Disabled entities will typically remain visible (if they have a visible appearance). */ readonly enabledResolved: Observable; /** * Get the instance of the ZComponent that constructed this entity. * * If you pass the class of a ZComponent as the `type` parameter, this function will ensure that it * returns an instance of that ZComponent. If this component or behavior was constructed by a different * ZComponent class, or by a different entity altogether, the function with `throw` an error. * * @param type The ZComponent class that you are expecting to receive * @returns The instance of the ZComponent that constructed this component or behavior */ getZComponentInstance(type?: ConstructorForComponent): T; /** * Register a function to be called when an Event is fired, or an Observable's value changes. * The function will only be bound to the underlying Event or Observable while this entity is enabled. * * Using this function, rather than attaching your handler directly to the Event or Observable, * ensures your handler is automatically released when this entity is disposed. * * @param evt The Event or Observable to listen to * @param fn A function that will be called when the event fires, or the Observable value changes */ register>(evt: Event, fn: (...args: Args) => void, priority?: number): any; register>(evt: Event, fn: (...args: Args) => void, options?: RegisterOptions): any; register(observable: Observable, fn: (v: Type) => void, priority?: number): any; register(observable: Observable, fn: (v: Type) => void, options?: RegisterOptions): any; /** * Unregisters a function that was previously registered to an Event or Observable. * * @param evt The Event or Observable * @param fn The function that was passed in the call to `register` */ unregister>(evt: Event, fn: (...args: Args) => void): any; unregister(observable: Observable, fn: (v: Type) => void): any; private _updateHandlers; /** * Destroy this entity, cleaning up any resources that it has created and * handler functions or callbacks it has registered. * * The base class implementation automatically unregisters any handler functions registered * using `register(...)`. * * Override this function in your own components and behaviors to clean up any resources * you have created. If you do override this function, end it with: * * ``` * return super.dispose(); * ``` * * This ensures that the dispose implementation of the parent class runs. * * @returns The result of a call to super.dispose() */ dispose(): never; private static callSuperDispose; } /** * Options that can be passed to the `register` function. */ export interface RegisterOptions { /** * The priority of the handler function. */ priority?: number; /** * If `true`, the handler function will be bound to the underlying Event or Observable even if this entity is disabled. */ bindWhenDisabled?: boolean; }