ManagedObject is the base class of most other framework classes, including Component.
Base class for objects that have their own unique ID, life cycle including active/inactive and destroyed states, and managed references to other instances.
Add an observer to all instances of this class and derived classes. The observer class is instantiated for each instance of this (observed) class, and its methods are automatically called when an event or property change occurs on the observed instance.
onExamplePropertyChange()– called when the value of
examplePropertychanges, or if a Change event is emitted on a managed object referenced by this (managed) property
onExamplePropertyChangeAsync()– idem, but called asynchronously, and only once if multiple changes occurred before this method was called
onExampleEventName()– called when an event with name
ExampleEventNameis emitted on the object; as an exception,
onChange()is called when any event that derives from
onExampleEventNameAsync()– idem, but called asynchronously
onEvent()– called when any event is emitted on the object
onEventAsync()– idem, but called asynchronously.
Note: Observer classes may be nested inside of the observed class, which provides access to private and protected methods; see
Attach an event handler function, to be invoked for all events that are emitted on all instances of this class and derived classes. Given function is invoked in the context (
this variable) of the emitting object, with the emitted event as a single parameter.
Unique ID of this managed object (read only).
The current lifecycle state of this managed object.
Note: This property is read-only. To change the state of a managed object (i.e. to move its lifecycle between active/inactive and destroyed states), use the
destroyManagedAsync methods. If any additional logic is required when moving between states, override the
onManagedStateDestroyingAsync methods in any class that derives from
Note: This property cannot be observed directly. Observer classes (see
addObserver) should use methods such as
onActive to observe lifecycle state.
Returns the current number of managed references that point to this object.
Note: Observers (see
addObserver) may use an
onReferenceCountChangeAsync method to observe this value asynchronously.
<TParent extends ManagedObject = ManagedObject>(ParentClass?:
If a class argument is specified, parent references are recursed until a parent of given type is found.
The object itself is never returned, even if it contains a managed child reference that points to itself.
Note: The reference to the managed parent (but not its events) can be observed (see
addObserver) using an
onManagedParentChangeAsync method on the observer.
<TEvent extends ManagedEvent = ManagedEvent, TConstructorArgs extends any = any>(e: string | TEvent | (new (...args: TConstructorArgs) => TEvent), ...constructorArgs: TConstructorArgs): this
Emit an event. If an event constructor is given, a new instance is created using given constructor arguments (rest parameters). If an event name (string) is given, a new plain event is created with given name.
For ways to handle events, see
@delegateEvents (for events that are emitted by referenced objects) or
ManagedObject.addObserver (static methods for class-based event handling).
Note: There is a limit to the number of events that can be emitted recursively; avoid calling this method on the same object from within a synchronous event handler.
(name?: string): void
Emit a change event (see
ManagedChangeEvent), to signal that the internal state of the emitting object has changed. The
name parameter is optional; if left out, the
CHANGE event (instance) is emitted directly.
.propagateChildEvents() protected deprecated
Deprecated: in favor of
@delegateEvents since version 3.1.
Activate this object (i.e. change state to
ManagedState.ACTIVATING and then to
onManagedStateActiveAsync methods are called in this process.
Deactivate this object, if it is currently active (i.e. change state to
ManagedState.DEACTIVATING and then to
onManagedStateInactiveAsync methods are called in this process.
Destroy this managed object (i.e. change state to
ManagedState.DESTROYING and then to
ManagedState.DESTROYED, clear all managed references from and to this object, and destroy all managed children); the
onManagedStateDestroyingAsync method is called in the process.
Note: Managed child objects are automatically destroyed when  their parent’s reference (decorated with
@component) is cleared or otherwise changed, or  the child object is removed from a managed list or map that is itself a managed child, or  when the parent object itself is destroyed.
Callback invoked when changing state to ‘active’, can be overridden to perform any actions before activating.
Callback invoked immediately after state has changed to ‘active’ and before any other state transitions, can be overridden.
Callback invoked when changing state to ‘inactive’, can be overridden to perform any actions before deactivating.
Callback invoked immediately after state has changed to ‘inactive’ and before any other state transitions, can be overridden.
Callback invoked when changing state to ‘destroyed’, can be overridden to perform any actions first.