Registers state-type triggers that automatically fire functions when key-value state is created, updated, or deleted within a scope. Use when building reactive side effects, change watchers, audit logs, cache invalidation, notification dispatchers, or any observer pattern where data changes should trigger downstream processing.
Comparable to: Firebase onSnapshot, Convex mutations
Use the concepts below when they fit the task. Not every state reaction needs all of them.
{ new_value, old_value, key, event_type } describing the changestate::set, state::update, and state::delete operationsstate::set, state::update, or state::delete
→ iii-state emits change event
→ registerTrigger type:'state' (scope match)
→ condition_function_id check (if configured)
→ registerFunction handler ({ new_value, old_value, key, event_type })
| Primitive | Purpose |
|---|---|
registerFunction | Define the reaction handler |
registerTrigger({ type: 'state' }) | Watch a scope for changes |
config: { scope, key, condition_function_id } | Scope filter and optional condition gate |
Event payload: { new_value, old_value, key, event_type } | Change details passed to the handler |
See ../references/state-reactions.js for the full working example — a reaction that watches a state scope and fires side effects when values change, with an optional condition gate.
Also available in Python: ../references/state-reactions.py
Also available in Rust: ../references/state-reactions.rs
Code using this pattern commonly includes, when relevant:
registerWorker(url, { workerName }) — worker initializationregisterFunction(id, handler) — define the reaction handlerregisterTrigger({ type: 'state', function_id, config: { scope, key, condition_function_id } }) — watch for changespayload.new_value / payload.old_value — compare before and afterpayload.event_type — distinguish between set, update, and delete eventstrigger({ function_id: 'state::set', payload }) — write derived state from the reactionconst logger = new Logger() — structured logging per reactionUse the adaptations below when they apply to the task.
scope to watch a specific domain (e.g. orders, user-profiles)key to narrow reactions to a single key within a scopecondition_function_id to filter — only react when the condition function returns truthyiii-state must be enabled in iii-config.yaml for state triggers to fire. See ../references/iii-config.yaml for the full annotated config reference.
iii-state-management.iii-trigger-conditions.iii-state-reactions when the primary need is automatic side effects on state changes.iii-state-reactions in the iii engine.