Function action

  • Wrap a function (or decorate a method) so that signals it reads are not added as dependencies to the current rule (if any). (Basically, it's shorthand for wrapping the function or method body in a giant call to peek().)

    So, instead of writing an action function like this:

    function outer(arg1, arg2) {
    return peek(() => {
    // reactive values used here will not be added to the running rule
    })
    }

    you can just write this:

    const outer = action((arg1, arg2) => {
    // reactive values used here will not be added to the running rule
    });

    or this:

    class Something {
    ⁣⁣@action // auto-detects TC39 or legacy decorators
    someMethod(arg1) {
    // reactive values used here will not be added to the running rule
    }
    }

    Type Parameters

    Parameters

    • fn: F

      The function to wrap. It can take any arguments or return value, and overloads are supported. However, any non-standard properties the function may have had will not be present on the wrapped function, even if TypeScript will act as if they are!

    Returns F

    A wrapped version of the function that passes through its arguments to the original function, while running with dependency tracking suppressed (as with peek()).