From c1cdf3660f82d725a85e073026d846b0a89423c6 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Wed, 17 Apr 2024 13:25:06 +0200 Subject: [PATCH] Allow changes to trigger event in ValueWidget after construction (messy still, but possible) --- packages/html2/src/index.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/html2/src/index.ts b/packages/html2/src/index.ts index dd03082..08ff25d 100644 --- a/packages/html2/src/index.ts +++ b/packages/html2/src/index.ts @@ -196,20 +196,21 @@ export class ValueWidget extends Widget { this._valueAsNumber = valueAsNumber; if ('value' in this.node) { - const readValues = (n: any) => { - this.suppressCycleWarning(); - this._value.value = n?.value ?? ''; - this._valueAsNumber.value = n?.valueAsNumber ?? NaN; - }; - - this.on(triggerEvent, e => readValues(e.target)); - readValues(this.node); + this.on(triggerEvent, () => this.readValues()); + this.readValues(); dataflow { this.valueAsNumber = this._valueAsNumber.value; } dataflow { this.value = this._value.value; } } } + readValues() { + const n = this.node as any; + this.suppressCycleWarning(); + this._value.value = n.value ?? ''; + this._valueAsNumber.value = n.valueAsNumber ?? NaN; + } + get value(): string { return this._value.value; }