Function peek

  • Runs the given function, while not subscribing the current scope when reading Store.Store values.

    Returns

    Whatever func() returns.

    Example

    import {Store, peek, text} from aberdeen

    let store = new Store(['a', 'b', 'c'])

    mount(document.body, () => {
    // Prevent rerender when store changes
    let msg = peek(() => `Store has ${store.count()} elements, and the first is ${store.get(0)}`))
    text(msg)
    })

    In the above example store.get(0) could be replaced with store.peek(0) to achieve the same result without peek() wrapping everything. There is no non-subscribing equivalent for count() however.

    Type Parameters

    • T

    Parameters

    • func: (() => T)

      Function to be executed immediately.

        • (): T
        • Returns T

    Returns T

Generated using TypeDoc