• Takes an object of key-value pairs containing ReadonlyVal instances and their corresponding ValSetValue functions, and returns a tuple containing an array of the ReadonlyVal instances and a function to set their values.

    Type Parameters

    • TValues extends {}

    Parameters

    Returns [{
        [K in string | number | symbol]: ReadonlyVal<TValues[K]>
    }, {
        [K in string | number | symbol]: ValSetValue<TValues[K]>
    }]

    Example

    const [vals, setVals] = groupVals({
    a: readonlyVal(1),
    b: readonlyVal(2),
    c: readonlyVal(3),
    });

    vals.a.value; // 1

    setVals.a(2);

    This is useful for classes that have multiple ReadonlyVal instances as properties.

    export interface Foo$ {
    a: ReadonlyVal<number>;
    b: ReadonlyVal<number>;
    c: ReadonlyVal<number>;
    }

    export class Foo {
    public $: Foo$;
    private setVals: { [K in keyof Foo$]: ValSetValue<UnwrapVal<Foo$[K]>> };

    public constructor() {
    const [vals, setVals] = groupVals({
    a: readonlyVal(1),
    b: readonlyVal(2),
    c: readonlyVal(3),
    });

    this.$ = vals;
    this.setVals = setVals;
    }