ReactiveDag.Op behaviour (reactive_dag v0.16.0)

Copy Markdown View Source

The behaviour a node's compute module implements — the recompute for ONE op, the per-cell unit of work.

A ReactiveDag.Node records its compute module in cell.meta.compute; the generic ReactiveDag.Node.Recompute strategy dispatches to it. The op reads its inputs (from the coordination tuples of its input cells, and/or the host's typed payload resources) and writes its output (its payload rows + its own coordination tuples), returning the keys that ACTUALLY changed — only those propagate, keeping the cascade O(real changes).

This is deliberately thin: the substrate says WHEN a cell recomputes and in what order; the op says HOW, in whatever storage/effect model the host uses (per-key Elixir calling an LLM, or a set-based SQL write). The library never inspects what an op does — only that it returns {:ok, changed_keys}.

A LEAF has no op: an external source writes its tuples and marks its parents dirty, so a leaf never reaches recompute.

Summary

Callbacks

Recompute keys of cell (or ["*"] for a whole-cell recompute). Return {:ok, changed_keys} — the subset whose output changed. Returning all keys is always correct, just less efficient.

Functions

Hard-delete keys of cell.

Mark key of cell present (opts carry host fields: source_ref, strength, …). Returns whatever the configured writer's put returns — :ok, or a boolean CHANGED signal an op can use (a writer that guards its upsert with IS DISTINCT FROM reports whether the row actually flipped).

Tombstone keys of cell (retain-if-vanish, if the writer supports it; else delete).

Types

key()

@type key() :: String.t()

Callbacks

recompute(cell, keys)

@callback recompute(cell :: ReactiveDag.Cell.t(), keys :: [key()]) :: {:ok, [key()]}

Recompute keys of cell (or ["*"] for a whole-cell recompute). Return {:ok, changed_keys} — the subset whose output changed. Returning all keys is always correct, just less efficient.

Functions

delete(cell, keys)

@spec delete(struct() | String.t(), [key()]) :: :ok

Hard-delete keys of cell.

put(cell, key, opts \\ [])

@spec put(struct() | String.t(), key(), keyword()) :: :ok | boolean()

Mark key of cell present (opts carry host fields: source_ref, strength, …). Returns whatever the configured writer's put returns — :ok, or a boolean CHANGED signal an op can use (a writer that guards its upsert with IS DISTINCT FROM reports whether the row actually flipped).

tombstone(cell, keys)

@spec tombstone(struct() | String.t(), [key()]) :: :ok

Tombstone keys of cell (retain-if-vanish, if the writer supports it; else delete).