Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spike: Software Design Patterns #3016

Closed
1 task done
denyo opened this issue Jan 29, 2024 · 0 comments · Fixed by #3038 · May be fixed by #3030
Closed
1 task done

Spike: Software Design Patterns #3016

denyo opened this issue Jan 29, 2024 · 0 comments · Fixed by #3038 · May be fixed by #3030
Assignees
Labels
component Adds or changes of the components team efficiency technical debt

Comments

@denyo
Copy link
Contributor

denyo commented Jan 29, 2024

Scope

We have several components that have identical props, behavior or events, e.g. all buttons, all links or form (wrapper) components.
Currently this identical behavior is maintained, synchronized and tested manually for the most part and differences are easy to miss. We call it redundant puzzles.

Therefore, we want to give some software design patterns a shot in order to extract the behavior introduced in #3009 which is duplicated in like 6 components.

While inheritance would probably be the best choice, stencil does not support it, however it seems

are possible.

Some 3rd party custom decorators:

Not sure if they would could be applied 1:1 but at least they can be used for reference.

Notes

Acceptance criteria

  • Decorators and Composition are evaluated in how they can help us to reduce the "redundant puzzles"

Conclusion

  • stencil decorators like @Prop, @Watch and @State need to stay in the stencil components, otherwise these don't work (most likely because of what happens in the stencil compiler which extracts decorated members only from components)
  • @use decorator mixes objects or classes into the stencil component, duplicate members/functions get overridden because of prototype merging, but this could be worked around with proper typing like prefixing lifecycle hooks with _ like _connectedCallback which are then called via mixin
  • reactive controller pattern hooks into lifecycles with one controller instance per component instance, no overriding or merging
  • extracting a type or interface for shared props works (e.g. class Button implements IBaseButton) but optional modifier doesn't force one to specify them which has impact on typings in wrappers, however, this could be corrected upon wrapper generation
  • demos: [SPIKE]: Software Design Patterns (Issue/3016) #3030
  • nice description from lit docs

Component composition is the process of assembling complex components from simpler components. A component can use subcomponents in its template. Components can use standard DOM mechanisms to communicate: setting properties on subcomponents, and listening for events from subcomponents.
Although component composition is the default way to think about breaking a complex Lit project down into smaller units, there are two other notable code patterns useful for factoring your Lit code:
Reactive controllers are objects that can hook into the update lifecycle of a Lit component, encapsulating state and behavior related to a feature into a separate unit of code.
Class mixins let you write reusable partial component definitions and "mix them in" to a component's inheritance chain.
Both mixins and reactive controllers let you factor component logic related to a given feature into a reusable unit.

@denyo denyo added component Adds or changes of the components to be refined issue has to be refined technical debt team efficiency labels Jan 29, 2024
@stephanschroeter stephanschroeter removed the to be refined issue has to be refined label Jan 30, 2024
@denyo denyo self-assigned this Feb 5, 2024
denyo added a commit that referenced this issue Feb 6, 2024
denyo added a commit that referenced this issue Feb 12, 2024
denyo added a commit that referenced this issue Feb 13, 2024
…heckbox-wrapper, pin-code, radio-button-wrappera and switch | bh | #3016
denyo added a commit that referenced this issue Feb 20, 2024
@denyo denyo assigned stephanschroeter and marcelbertram and unassigned denyo Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment