Skip to contents

Evaluates cases in order against a bound value and renders the body of the first case whose predicate is TRUE. Records are projected as a mini-store for the active case's body; scalars are passed as the bare callable. On active-case change, the previous case is torn down (its reactives, DOM, and mini-store) and the new case is mounted fresh.

Usage

Match(callable, ...)

Arguments

callable

The bound value — any 0-arg callable. Records (named lists) are projected as a mini-store; scalars are passed as the bare callable.

...

One or more Case() / Default() values.

Value

A irid control-flow node.

Details

Use a choice function as the leading callable to fold unrelated reactive state into a tagged variant on the fly:

Match(\() if (loading()) list(tag = "loading") else list(tag = "data", x = data()),
  Case(\(r) r$tag == "loading", \() Spinner()),
  Case(\(r) r$tag == "data",    \(r) Items(r$x))
)

Conceptually, When() is a fixed-shape binary specialization of Match.