Lavash.Rx.Graph (Lavash v0.4.0-rc.1)

Copy Markdown View Source

A precomputed reactive dependency graph.

Built at compile time (via module attribute) or at runtime, then passed to Lavash.Reactive functions to drive state updates.

The graph contains:

  • topo_order — derived fields in topological order for recomputation
  • dependents — reverse index: field → list of derived fields that depend on it
  • deps — forward index: derived field → list of fields it depends on
  • compute_fns — derived field → function that computes it from deps
  • state_defaults — state field → default value
  • tags — reverse index: tag → MapSet of field names (for resource invalidation, etc.)

Summary

Functions

Returns all derived fields transitively affected by the given dirty fields.

Compiles states and derives into a frozen %Graph{}.

Returns field names that have the given tag.

Filters topo_order to only the affected fields, preserving correct evaluation order.

Functions

affected(graph, dirty_fields)

Returns all derived fields transitively affected by the given dirty fields.

compile(states, derives)

Compiles states and derives into a frozen %Graph{}.

States: [{name, default}, ...] Derives: [{name, [dep, ...], fun, async?} | {name, [dep, ...], fun, async?, [tag]}]

The function for each derive receives a map of dependency values: fn %{count: 5, step: 2} -> 10 end

fields_with_tag(graph, tag)

Returns field names that have the given tag.

recompute_order(graph, dirty_fields)

Filters topo_order to only the affected fields, preserving correct evaluation order.