Documentation

ManagedMap

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

Managed objects

This class is part of a group of managed object classes. See Understanding components for details.

See also

ManagedList, ManagedObject, ManagedReference.

class ManagedMap

extends ManagedObject

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

Child references

If a managed object property that is decorated with @managedChild gets assigned a ManagedMap instance, the parent-child relationship will extend to the items in this ManagedMap. In other words, the items in a ManagedMap that is itself a managed child object, will become managed children of the map itself.

In this case, removing objects from the ManagedMap object will destroy these objects. Adding objects to the ManagedMap will ‘move’ them from their current parent, if any.

Example

let m = new ManagedMap();
let obj = ManagedRecord.create({ foo: "bar" });
m.set("baz", obj);
m.has("baz") // true
m.get("baz") // => obj

Constructor

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

.propagateEvents()

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

Propagate events from objects in this map by emitting them on the map object itself, optionally restricted to given types of events.

.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

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).

  • key — The key to be mapped to given object.

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

.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.

.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

[1]. (): ManagedObject
[2]. <TParent extends 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.

.propagateChildEvents() protected

[1]. (f?: (this: this, e: ManagedEvent, propertyName: string) => void | ManagedEvent | ManagedEvent[]): this
[2]. (...types: (ManagedEvent | (new (...args: any[]) => ManagedEvent))[]): 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.