ManagedParentChangeEvent

class ManagedParentChangeEvent

extends ManagedCoreEvent

Event that is emitted when a managed object is assigned to a managed child reference property (see @managedChild decorator); the child object emits this event, with parent set to the new parent object.

Example

The following example shows how this event can be observed on a component (or other managed object).

class MyChildComponent extends Component { }

// observe the event on the above class:
MyChildComponent.observe(class {
  onManagedParentChange(e: ManagedParentChangeEvent) {
    if (e.parent instanceof MyParentComponent) {
      console.log("New parent: " + e.parent.foo);
    }
  }
})

class MyParentComponent extends Component {
  constructor (public readonly foo: string) {
    super();
  }

  // this is a managed child property so assigning
  // a component here triggers the event
  @managedChild
  foo = new MyChildComponent();
}

let c = new MyChildComponent();
let a = new MyParentComponent("a");
a.foo = c;  // => New parent: a
let b = new MyParentComponent("b");
b.foo = c;  // => New parent: b

Constructor

(parent: ManagedObject): ManagedParentChangeEvent

.parent

ManagedObject

The new parent object.

.name

string

Inherited from ManagedEvent.name.

.freeze()

(): Readonly<this>

Inherited from ManagedEvent.freeze.