From 5e7fcf9fa84d6552dc1a10eaa2992610bb566573 Mon Sep 17 00:00:00 2001 From: Rob Barber Date: Mon, 7 Dec 2020 09:08:13 -0800 Subject: [PATCH] Automatically updating proxy on attribute changes --- .../fast-element/src/attributes.ts | 6 ++- .../src/observation/observable.ts | 4 ++ .../fast-foundation/src/button/button.ts | 29 ----------- .../fast-foundation/src/checkbox/checkbox.ts | 14 +----- .../src/form-associated/form-associated.ts | 44 ++++++---------- .../src/listbox-option/listbox-option.ts | 27 +++------- .../fast-foundation/src/radio/radio.ts | 9 ---- .../fast-foundation/src/slider/slider.ts | 20 +------- .../fast-foundation/src/switch/switch.ts | 8 --- .../src/text-area/text-area.ts | 30 ----------- .../src/text-field/text-field.ts | 50 +++---------------- 11 files changed, 41 insertions(+), 200 deletions(-) diff --git a/packages/web-components/fast-element/src/attributes.ts b/packages/web-components/fast-element/src/attributes.ts index 6c6ed79d7ab..a5d02d1c89a 100644 --- a/packages/web-components/fast-element/src/attributes.ts +++ b/packages/web-components/fast-element/src/attributes.ts @@ -175,7 +175,7 @@ export class AttributeDefinition implements Accessor { * @param source - The source element to access. * @param value - The value to set the attribute/property to. */ - public setValue(source: HTMLElement, newValue: any): void { + public setValue(source: any, newValue: any): void { const oldValue = source[this.fieldName]; const converter = this.converter; @@ -192,6 +192,10 @@ export class AttributeDefinition implements Accessor { source[this.callbackName](oldValue, newValue); } + if (source.updateProxy) { + source.updateProxy(this.name, newValue); + } + ((source as any).$fastController as Notifier).notify(this.name); } } diff --git a/packages/web-components/fast-element/src/observation/observable.ts b/packages/web-components/fast-element/src/observation/observable.ts index d5a65d94882..3aaf408b32a 100644 --- a/packages/web-components/fast-element/src/observation/observable.ts +++ b/packages/web-components/fast-element/src/observation/observable.ts @@ -63,6 +63,10 @@ class DefaultObservableAccessor implements Accessor { callback.call(source, oldValue, newValue); } + if (source.updateProxy) { + source.updateProxy(this.name, newValue); + } + /* eslint-disable-next-line @typescript-eslint/no-use-before-define */ getNotifier(source).notify(this.name); } diff --git a/packages/web-components/fast-foundation/src/button/button.ts b/packages/web-components/fast-foundation/src/button/button.ts index 2b971f11dcd..f157ebc2266 100644 --- a/packages/web-components/fast-foundation/src/button/button.ts +++ b/packages/web-components/fast-foundation/src/button/button.ts @@ -39,11 +39,6 @@ export class Button extends FormAssociatedButton { */ @attr public formaction: string; - private formactionChanged(): void { - if (this.proxy instanceof HTMLElement) { - this.proxy.formAction = this.formaction; - } - } /** * See {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button |