| 759 | } |
| 760 | |
| 761 | sub<K extends keyof T>(tag: K, update_func?: ((val: T[K]) => void) | undefined): DialogField<T[K]> { |
| 762 | return new DialogField<T[K]>( |
| 763 | this.#dialog, |
| 764 | () => this.get()[tag], |
| 765 | (val) => { |
| 766 | const container = this.get(); |
| 767 | if (Array.isArray(container) && typeof tag == "number") |
| 768 | this.#setter(toSpliced(container, tag, 1, val) as T); |
| 769 | else |
| 770 | this.#setter({ ...container, [tag]: val }); |
| 771 | if (update_func) |
| 772 | update_func(val); |
| 773 | }, |
| 774 | this.#path ? this.#path + "." + String(tag) : String(tag) |
| 775 | ); |
| 776 | } |
| 777 | |
| 778 | at<TT extends T>(witness: TT): DialogField<TT> { |
| 779 | cockpit.assert(Object.is(witness, this.get())); |