deven-org / boiler

A fully customisable and tokenised design system boilerplate built by Accenture Song
https://boilerds.com/
MIT License
14 stars 6 forks source link

Code quality: Improve consistency for property initialisation and defaulting #1083

Open faselbaum opened 2 months ago

faselbaum commented 2 months ago

Description / User story

As a developer, I want to have consistent initialisation and defaulting of property declarations so that we can get rid of inline nullish checking. This is currently very inconsistent across component implementations and bloats our code.

Eg.: Some components declare and initialize properties like this

@property sizeVariant?: FormSizesType = 'md'

VS

@property sizeVariant: FormSizesType = 'md'

The latter one means that from a compiler perspective sizeVariant will always be defined and does not need to be validated upon usage, reducing nullish checking operations in many parts of the code. This leads to better readability. This is just a simple example though and doesn't account for the fact that our properties and state are potentially initialized from attribute values or might be changed to invalid values from javascript.

We need to find a general strategy on how exactly we want to do this and then implement this strategy for all components.

Possible Solutions

A) Use custom accessors for defaulting and sanitizing - https://lit.dev/docs/components/properties/#accessors B) Use willUpdate lifecycle callback for defaulting and sanitizing - https://lit.dev/docs/components/lifecycle/#willupdate

Requirements / Prerequisites

Acceptance Criteria

Additional information

Code of Conduct

faselbaum commented 1 week ago

Note

This issue and it's related implementation #1083 need to be revisited when / if #507 make it into the develop branch. The SanitizationController needs to be adapted to use the SignalHub instead of lit's update lifecycle hook.