class ManagedRecord
A class that can be used to describe data models based on ManagedObject.
class ManagedRecord extends ManagedObject
Description
For the most part, ManagedRecord objects behave exactly like ManagedObject instances. The ManagedRecord class only adds two features on top of the functionality offered by ManagedObject:
- A static create() method, which constructs a new instance (without any arguments), and then applies a given set of properties.
- Methods for finding parent records (instances of ManagedRecord), and siblings in a ManagedList.
Example
// Create a ManagedRecord that holds other records
class MyItem extends ManagedRecord {
name = "";
readonly list = this.attach(new MangedList<MyItem>());
}
let item = MyItem.create({ name: "root" });
item.list.add(
MyItem.create({ name: "one" }),
MyItem.create({ name: "two" })
);
item.list.first().name // => "one"
item.list.first().getParentRecord() // => item
item.list.first().getNextSibling()?.name // => "two"
Type Members
- type ManagedRecord.PartialProperties staticType definition for the set of properties passed to ManagedRecord.create().
Static Members
- ManagedRecord.create(this, properties?) staticCreates a new instance of this class, with the provided property values.
Instance Members
- getParentRecord(ParentClass?)Returns the parent record (or parent’s parent, etc.) that’s an instance of the provided class.
- getNextSibling()Returns the next record in a parent list, if any.
- getPreviousSibling()Returns the previous record in a parent list, if any.
Inherited Members
- emit(event)Emits an event, immediately calling all event handlers.
- emitChange(name?, data?)Emits a change event, an instance of ManagedChangeEvent.
- listen(handler)Adds a handler for all events emitted by this object.
- isUnlinked()Returns true if the object has been unlinked.
- unlink()Unlinks this managed object.
- beforeUnlink() protectedA method that’s called immediately before unlinking an object, can be overridden.
- attach(target, observer?) protectedAttaches the provided managed object to this object.
- autoAttach(propertyName, observer?) protectedObserves a property, so that any object assigned to it is attached immediately.