Documentation

attach()

Attaches the specified observable object to this object.

protected attach<T extends ObservableObject>(
target: T,
listener?: ObservableObject.AttachListener<T>,
): T;

Notes

Parameters

Return value

The newly attached object

Errors

This method throws an error if the provided object was unlinked, or if a loop is detected (i.e. the target object would be indirectly attached to itself).

Examples

// Attach an object once, in the constructor
class MyObject extends ObservableObject {
  foo = "bar";
}
class ParentObject extends ObservableObject {
  readonly target = this.attach(
    new MyObject(),
    (event) => {
      // ... handle event
    }
  )
}

Related