Skip to content

Commit

Permalink
fast-element: Simplify fromView logic and element-controller checks (#…
Browse files Browse the repository at this point in the history
…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 <[email protected]>
  • Loading branch information
doguabaris and janechu authored Dec 11, 2024
1 parent 4d0c976 commit 51a79eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fast-element: Simplify conditional checks in element-controller",
"packageName": "@microsoft/fast-element",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
);
},
};

Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 51a79eb

Please sign in to comment.