Exploration of a conditional trigger primitive that fires actions when a boolean expression transitions between true and false, rather than on every state change.
Trigger(
"{{ cart_total > 100 }}",
on_true=ServerAction("/api/apply-discount"),
on_false=ServerAction("/api/remove-discount"),
)
This would be distinct from Computed (which derives values) and from component on_change handlers (which react to specific user interactions). A trigger would react to state crossing a threshold, regardless of what caused the change.
Composes naturally with Computed: the expression can reference computed keys, and computed keys can encode the conditions. The trigger just detects the transition.
This came out of the discussion that led to removing Watch (#283). Watch was designed to fire actions on any state change, but its primary use cases (derived state, normalization) were better served by Computed. The one gap neither Computed nor on_change fills is threshold/condition-based reactions: "when this expression becomes true, do something." That's what this would address.
Note: This doesn't have a strong concrete use case yet. Filing to capture the design direction for when one emerges.
Exploration of a conditional trigger primitive that fires actions when a boolean expression transitions between true and false, rather than on every state change.
This would be distinct from
Computed(which derives values) and from componenton_changehandlers (which react to specific user interactions). A trigger would react to state crossing a threshold, regardless of what caused the change.Composes naturally with
Computed: the expression can reference computed keys, and computed keys can encode the conditions. The trigger just detects the transition.This came out of the discussion that led to removing
Watch(#283). Watch was designed to fire actions on any state change, but its primary use cases (derived state, normalization) were better served byComputed. The one gap neitherComputednoron_changefills is threshold/condition-based reactions: "when this expression becomes true, do something." That's what this would address.Note: This doesn't have a strong concrete use case yet. Filing to capture the design direction for when one emerges.