Skip to main content

Goal

Run a Function whenever a specific state value changes, using a state trigger.

Steps

1. Enable the State module

iii-config.yaml

2. Register the Function

The state trigger fires whenever the watched scope/key pair changes. The handler receives an event with key, new_value, old_value, scope, and event_type properties.
state-watcher.ts

3. Register the state trigger

Each state trigger watches a single scope/key pair. To react to multiple keys, register a function and trigger for each.
state-trigger.ts

Result

When any Function writes to the watched scope/key pair via state::set or state::update, the Engine automatically invokes the registered handler with the new value.