data
function data<Tag>(instance): Effect<EntityByTag<Tag>, never, Runner>;
Function: data()
function data<Tag>(instance): Effect<EntityByTag<Tag>, never, Runner>;Defined in: packages/motion/src/Scene.ts:678
Read an entity's current data.
Type Parameters
| Type Parameter |
|---|
Tag extends | "Audio" | "Line" | "Path" | "Rect" | "Circle" | "Ellipse" | "Text" | "Group" | "Hud" | "Image" | "Camera" |
Parameters
| Parameter | Type | Description |
|---|---|---|
instance | Instance<Tag> | Handle to read. |
Returns
Effect<EntityByTag<Tag>, never, Runner>
The entity's data as of this frame.
Remarks
An Instance is only a handle, so this is how you get at the live values behind it — to branch on where something is, or to compute a target relative to its current state.
The result is a snapshot for THIS frame, not a live view; read again on a
later frame to see later values. The returned type is narrowed by the
handle's kind, so a Circle's radius is available without casting.
Reading a destroyed entity is a loud defect rather than a silent
undefined.
See
update to write it.
Example
const { position, radius } = yield* Scene.data(dot);
yield* dot.pipe(Motion.moveTo({ x: position.x + radius * 4 }, "1 second"));