From 51a79eb3294897fb1e71b5dcdcce0bea62521e80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fu=20Abaris?= <135986694+doguabaris@users.noreply.github.com> Date: Wed, 11 Dec 2024 18:16:40 +0100 Subject: [PATCH] fast-element: Simplify fromView logic and element-controller checks (#7047) * fast-element: Simplify fromView condition in attributes Replace the ternary operator with a direct negation in the fromView method. This change enhances code readability and ensures consistent handling of null, undefined, false, and zero values. * fast-element: Update parameter name in setValue method Renamed the `value` parameter to `newValue` in the `setValue` method of the `attributes.ts` file. * fast-element: Simplify conditional checks in element-controller Replaced explicit boolean comparisons with direct truthy and falsy checks in the `connectBehaviors` and `disconnectBehaviors` methods. * docs(fast-element): improve JSDoc for AttributeDefinition setValue method - Added a detailed description for the newValue parameter in the setValue method. - Ensures better clarity and documentation for the method's functionality. * Restore explicit boolean checks in element-controller methods --------- Co-authored-by: Jane Chu <7559015+janechu@users.noreply.github.com> --- ...fast-element-b679d332-e9c0-4e4a-984b-c06481f24caa.json | 7 +++++++ .../fast-element/src/components/attributes.ts | 8 ++++---- 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 change/@microsoft-fast-element-b679d332-e9c0-4e4a-984b-c06481f24caa.json diff --git a/change/@microsoft-fast-element-b679d332-e9c0-4e4a-984b-c06481f24caa.json b/change/@microsoft-fast-element-b679d332-e9c0-4e4a-984b-c06481f24caa.json new file mode 100644 index 00000000000..6a3fb2c8173 --- /dev/null +++ b/change/@microsoft-fast-element-b679d332-e9c0-4e4a-984b-c06481f24caa.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "fast-element: Simplify conditional checks in element-controller", + "packageName": "@microsoft/fast-element", + "email": "abaris@null.net", + "dependentChangeType": "patch" +} diff --git a/packages/web-components/fast-element/src/components/attributes.ts b/packages/web-components/fast-element/src/components/attributes.ts index 0177cb15ee5..994ae871eaa 100644 --- a/packages/web-components/fast-element/src/components/attributes.ts +++ b/packages/web-components/fast-element/src/components/attributes.ts @@ -80,13 +80,13 @@ export const booleanConverter: ValueConverter = { }, fromView(value: any): any { - return value === null || + return !( + value === null || value === void 0 || value === "false" || value === false || value === 0 - ? false - : true; + ); }, }; @@ -202,7 +202,7 @@ export class AttributeDefinition implements Accessor { /** * Sets the value of the attribute/property on the source element. * @param source - The source element to access. - * @param value - The value to set the attribute/property to. + * @param newValue - The value to set the attribute/property to. */ public setValue(source: HTMLElement, newValue: any): void { const oldValue = source[this.fieldName];