ManagedRecord

class ManagedRecord

extends Component

Managed record base class. Represents data that is managed (as ManagedObject), with additional methods to managed inward references — especially useful for constructing the application model.

Example 1

The following example shows how to create and manage custom record classes.

class MyFooItem extends ManagedRecord {
  constructor (public readonly foo: string) {
    super();
  }
}

class MyModel extends ManagedRecord {
  @managedChild
  items = new ManagedList().restrict(MyFooItem);
}

let m = new MyModel();
m.items.add(new MyFooItem("foo"));
m.items.add(new MyFooItem("bar"));
m.items.first()!.getParentRecord()  // => m
m.items.first()!.getNextSibling()!.foo  // "bar"

Example 2

The following example shows how to create records without a custom class.

let r = ManagedRecord.create({
  foo = "bar",
  x = "yz"
});
r.foo = "baz";

Constructor

(): ManagedRecord

.validate()

(): void

Validate the data represented by this record. To be overridden by specific record classes, which should also always call super.validate(). Multiple (nested) errors may be thrown using the ManagedRecordValidationError constructor.

.getManagedReferrers() protected

<TResult extends ManagedObject = ManagedObject>(skipCoreObjects?: boolean, FilterByClass?: ManagedObjectConstructor<TResult>): TResult[]

Returns an array of unique managed objects that contain managed references to this object (see @managed, @managedChild, @managedDependency, and @compose decorators).

  • skipCoreObjects — Set to true to include referrers of (nested) lists, maps, and reference instances (i.e. ‘core’ objects), not those objects themselves.

  • FilterByClass — If specified, results will only include instances of given class. Other referrers are not inspected recursively.

.getReferrerRecords()

<TResult extends ManagedRecord = ManagedRecord>(FilterByClass?: ManagedObjectConstructor<TResult>): TResult[]

Returns an array of unique records that contain managed references to this object (see @managed, @managedChild, @managedDependency, and @compose decorators). This includes records that refer directly to this object, as well as those that refer to managed list(s) or map(s) that contain this record.

  • FilterByClass — If specified, results will only include instances of given class. Other referrers are not inspected recursively.

.getParentRecord()

[1]. (): ManagedRecord
[2]. <TParent extends ManagedRecord>(ParentClass: ManagedObjectConstructor<TParent>): TParent

[1] Returns the current parent record. See @managedChild decorator.

[2] Returns the parent record (or parent’s parent, etc.) of given type. See @managedChild decorator.

.getNextSibling()

<TResult = this>(): TResult

Returns the next record in a parent list (i.e. a list that is a child object of another record).

.getPreviousSibling()

<TResult = this>(): TResult

Returns the previous record in a parent list (i.e. a list that is a child object of another record).

.isPresetComponent() protected

(): boolean

Inherited from Component.isPresetComponent.

.getParentComponent()

[1]. (): Component
[2]. <TParent extends Component>(ParentClass: ComponentConstructor<TParent>): TParent

Inherited from Component.getParentComponent.

.getCompositeParent()

<TParent extends Component>(ParentClass?: ComponentConstructor<TParent>): TParent

Inherited from Component.getCompositeParent.

.propagateComponentEvent()

(name: string, inner?: ManagedEvent): void

Inherited from Component.propagateComponentEvent.

.managedId

number

Inherited from ManagedObject.managedId.

.managedState

ManagedState

Inherited from ManagedObject.managedState.

.getReferenceCount() protected

(): number

Inherited from ManagedObject.getReferenceCount.

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


ManagedRecord.create

<T extends object>(properties?: T): ManagedRecord & { [p in keyof T]: T[p]; }

Create a new instance of ManagedRecord that contains given properties. All values are copied directly onto the new instance.


ManagedRecord.isValidationError

(err: any): err is ManagedRecordValidationError

Checks if given error is a ManagedRecordValidationError object.