Reactive APIs
    Preparing search index...
    • Watches a single reactive value and executes a callback whenever that value changes.

      This function is the synchronous variant of watchValue. It will re-execute after every fine grained change, even if those changes occur in immediate succession. syncWatchValue should therefore be considered a low level primitive, for most use cases watchValue should be the right tool instead.

      Example:

      import { reactive, syncWatchValue } from "@conterra/reactivity-core";

      const v1 = reactive(1);
      const v2 = reactive(2);

      // Executes whenever the _sum_ of the two values changes.
      syncWatchValue(() => v1.value + v2.value, (sum) => {
      console.log("new sum", sum);
      });

      syncWatchValue returns a handle that can be used to unsubscribe from changes. That handle's destroy() function should be called to stop watching when you are no longer interested in updates:

      const handle = syncWatchValue(() => someReactive.value, () => {
      // ...
      });
      // later:
      handle.destroy();

      NOTE: You must not modify the parameters that get passed into callback.

      Type Parameters

      • T

      Parameters

      • selector: ReactiveGetter<T>

        a function that returns the value to watch.

      • callback: WatchCallback<T>

        a function that will be executed whenever the watched value changes.

      • Optionaloptions: WatchOptions<T> & { immediate?: false }

        additional options.

      Returns CleanupHandle

    • This overload is used when immediate is not set to false.

      Type Parameters

      • T

      Parameters

      Returns CleanupHandle