Skip to content

Trigger: conditional actions when expressions transition #299

@jlowin

Description

@jlowin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImprovement to existing functionality or new capabilities.pythonRelated to the Python SDK: components, actions, serialization.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions