Subscribe to the event that an entity of a specific type is created.
The entity type to subscribe to, or * to subscribe to the creation of all entity types.
The callback called right after the entity is created.
The entity that was just created.
Optionally a function that's called when the created entity is removed.
A terminable that when terminated will stop dispatching new onCreate events. Cleanup functions that were returned during entity creation will still be called on removal of the entity.
Subscribe to the event that some pointer in the document starts pointing to a given location.
The location that is being pointed to
Called right after from starts pointing to to.
The location that points to to. from is always the location of a pointer field.
Whether the callback should be executed immediately with all pointers pointing to to.
A terminable that when terminated will stop dispatching new onPointingTo events.
const tm = await nexus.modify(t => t.create("tonematrix", {}))
nexus.events.onPointingTo(tm.fields.audioOutput, (from) =>
console.debug(
"pointing from field",
from.toString(),
"which is entity",
nexus.queryEntities.getEntity(from.entityId)?.id
))
If the pointer is the result of an entity being created, then onCreate is called before this callback.
Subscribe to an event where an entity is removed.
The entity whose removal triggers the callback, or * to subscribe to the removal of all entities.
The callback called right after the entity is removed.
The entity that was just removed.
A terminable that when terminated will stop dispatching new onRemove events.
Subscribe to the event that some pointer in the document stops pointing to a given location.
The location that is being stopped pointing to.
Called right after from stops pointing to to.
The location that stops pointing to to. from is always the location of a pointer field.
A terminable that when terminated will stop dispatching new onStopPointingTo events.
const tm = await nexus.modify(t => t.create("tonematrix", {}))
nexus.events.onStopPointingTo(tm.fields.audioOutput, (from) =>
console.debug("pointing from field", from.toString(), "which is entity", nexus.queryEntities.getEntity(from.entityId)?.id
))
If the pointer is the result of an entity being removed, then onRemove is called after this callback.
Subscribe to updates of a mutable primitive field in the nexus document.
primitive field whose updates are subscribed to
The callback called right after the update.
Whether the callback should be triggered immediately with the current value of the field
A terminable that when terminated will stop dispatching new onUpdate events.
Can be used to subscribe to changes in the document.
Events for all existing entities are dispatched after index.SyncedDocument.start is called; after this, they are dispatched either:
Example
When modifying the document using the document.TransactionBuilder, the event callbacks are executed immediately during the callback that creates the modification(s).
Example