Aberdeen - v1.0.3
    Preparing search index...

    Function peek

    • Executes a function without creating subscriptions in the current reactive scope, and returns its result.

      This is useful when you need to access reactive data inside a reactive scope (like observe) but do not want changes to that specific data to trigger a re-execute of the scope.

      Type Parameters

      • T

        The type of the return value of your function.

      Parameters

      • func: () => T

        The function to execute without creating subscriptions.

      Returns T

      Whatever func returns.

      const data = proxy({ a: 1, b: 2 });
      observe(() => {
      // re-executes only when data.a changes, because data.b is peeked.
      const b = peek(() => data.b);
      console.log(`A is ${data.a}, B was ${b} when A changed.`);
      });
      data.b = 3; // Does not trigger console.log
      data.a = 2; // Triggers console.log (logs "A is 2, B was 3 when A changed.")