ManagedMap

Managed maps contain indexed sets of references to other managed objects.

class ManagedMap

extends ManagedObject

Represents an unordered list of managed objects that are indexed using unique key strings.

See also: Concepts > Lists and maps

Constructor

<T extends ManagedObject = ManagedObject>(): ManagedMap<T>

.propagateEvents()

[1]. (f?: (this: this, e: ManagedEvent) => void | ManagedEvent | ManagedEvent[]): this
[2]. (...types: (ManagedEvent | (new (...args: any[]) => ManagedEvent))[]): this

[1] Propagate events from all objects in this map by emitting the same events on the map object itself.

If a function is specified, the function can be used to transform one event to one or more others, or stop propagation if the function returns undefined. The function is called with the event itself as its only argument.

[2] Propagate events from all objects in this map by emitting the same events on the map object itself.

If one or more event classes are specified, only events that extend given event types are propagated.

Note: Calling this method a second time replaces the current propagation rule/function.

.restrict()

<T extends ManagedObject>(classType: ManagedObjectConstructor<T>): ManagedMap<T>

Ensure that objects in this map are all instances of given class (or a sub class), and restrict newly mapped objects to instances of given class. Given class must be a sub class of ManagedObject.

.get()

(key: string): T

Returns the current object mapped to given key, if any.

.has()

(key: string): boolean

Returns true if any object is currently mapped to given key.

.unset()

(key: string): void

Remove the mapping for given key.

Note: Does not throw an error if given key was not mapped to any object at all.

.set()

(key: string, target?: T): void | this

  • key — The key to be mapped to given object.
  • target — The managed object (or list, or map) to be mapped to given key.

Map given object (or managed list or map) to given key, removing the existing mapping between the same key and any other object, if any.

Objects may be mapped to multiple keys at the same time, unless the ManagedMap instance itself is a child object of a managed object or list (see @managedChild decorator).

.remove()

(target: T): this

Remove given object from this map (same as calling unset(...) on all keys that refer to given object).

.clear()

(): this

Remove all objects from this map.

.objects()

(): T[]

Returns a list of all (unique) objects in this map.

.keys()

(): string[]

Returns a list of all keys in this map.

.forEach()

(callback: (key: string, target: T) => void): void

  • callback — the function to be called, with a key and a single object as the only argument.

Iterates over the keys in this list and invokes given callback for each key and object.

Note: The behavior of this method is undefined if objects are inserted by the callback function.

.includes()

(target: T): boolean

Returns true if given object is currently contained in this map.

.toObject()

(): { [index: string]: T; }

Returns an object with properties for all keys and objects in this map.

.toJSON()

(): any

Returns an object representation of this map (alias of toObject method).

.weakRef()

(): this

Stop newly referenced objects from becoming child objects even if this ManagedMap instance itself is held through a child reference (by a parent object); this can be used to automatically dereference objects when the parent object is destroyed.

.managedId

number

Inherited from ManagedObject.managedId.

.managedState

ManagedState

Inherited from ManagedObject.managedState.

.getReferenceCount() protected

(): number

Inherited from ManagedObject.getReferenceCount.

.getManagedReferrers() protected

(): ManagedObject[]

Inherited from ManagedObject.getManagedReferrers.

.getManagedParent() protected

<TParent extends ManagedObject = ManagedObject>(ParentClass?: ManagedObjectConstructor<TParent>): TParent

Inherited from ManagedObject.getManagedParent.

.emit()

<TEvent extends ManagedEvent = ManagedEvent, TConstructorArgs extends any[] = any[]>(e: string | TEvent | (new (...args: TConstructorArgs) => TEvent), ...constructorArgs: TConstructorArgs): this

Inherited from ManagedObject.emit.

.emitChange()

(name?: string): void

Inherited from ManagedObject.emitChange.

.propagateChildEvents() protected deprecated

(...types: ((new (...args: any[]) => ManagedEvent) | ((e: ManagedEvent) => any))[]): this

Inherited from ManagedObject.propagateChildEvents.

.activateManagedAsync() protected

(): Promise<any>

Inherited from ManagedObject.activateManagedAsync.

.deactivateManagedAsync() protected

(): Promise<void>

Inherited from ManagedObject.deactivateManagedAsync.

.destroyManagedAsync() protected

(): Promise<void>

Inherited from ManagedObject.destroyManagedAsync.

.onManagedStateActivatingAsync() protected

(): Promise<void>

Inherited from ManagedObject.onManagedStateActivatingAsync.

.onManagedStateActiveAsync() protected

(): Promise<void>

Inherited from ManagedObject.onManagedStateActiveAsync.

.onManagedStateDeactivatingAsync() protected

(): Promise<void>

Inherited from ManagedObject.onManagedStateDeactivatingAsync.

.onManagedStateInactiveAsync() protected

(): Promise<void>

Inherited from ManagedObject.onManagedStateInactiveAsync.

.onManagedStateDestroyingAsync() protected

(): Promise<void>

Inherited from ManagedObject.onManagedStateDestroyingAsync.