Skip to main content

effect

Macro effect 

Source
effect!() { /* proc-macro */ }
Expand description

The effect! macro for creating order-independent effects with dependencies.

This is the recommended way to create effects in Telex. Unlike traditional hooks, effects created with this macro can be used conditionally or in any order without causing issues.

Each macro invocation creates a unique anonymous type as the key, ensuring each call site gets its own independent effect.

ยงExamples

Basic usage - runs when count changes:

โ“˜
effect!(cx, count.get(), |&c| {
    println!("count changed to {}", c);
    || {}  // cleanup function
});

Safe in conditionals:

โ“˜
if show_logger {
    effect!(cx, value.get(), |&v| {
        println!("value: {}", v);
        || {}
    });
}

Multiple dependencies via tuple:

โ“˜
effect!(cx, (a.get(), b.get()), |&(a, b)| {
    println!("a={}, b={}", a, b);
    || {}
});