• Similar to watch(value) this method wraps a list of values with a single IWatcher instance and tracks access to properties (sub-properties) of each individual element of the values list.

    See

    WatchAllResult

    Returns

    WatchAllResult object that holds the proxies for the values and watcher object that tracks property access and does the comparison.

    Example

    Here's an example with different objects, but unchanged accessed properties:

    import { watchAll } from '@indutny/sneequals';

    const values = [{ a: { b: 1 } }, { c: 2 }];
    const { proxies, watcher } = watchAll(value);
    const derived = watcher.unwrap({ b: proxies[0].a.b, c: proxies[1].c });

    // Further access to `proxy` (or its sub-proxies) would throw.
    watcher.stop();

    // Prints `{ b: 1, c: 2 }`
    console.log(derived);

    // Prints `false` because the tracked `value.a.b` didn't change.
    console.log(watcher.isChanged(values[0], { a: { b: 1 } }));

    // Prints `true` because the tracked `value.c` changed.
    console.log(watcher.isChanged(values[1], { c: 3 }));

    Type Parameters

    • Values extends readonly unknown[]

    Parameters

    • values: Values

      list of input values that could be plain objects, arrays, functions or primitives.

    Returns Readonly<{
        proxies: Values;
        watcher: IWatcher;
    }>

Generated using TypeDoc