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;
}
Takes an object of key-value pairs containing
ReadonlyVal
instances and their correspondingValSetValue
functions, and returns a tuple containing an array of theReadonlyVal
instances and a function to set their values.