chore: fix scoping issues, usage of instanceof#8822
Merged
vladitasev merged 2 commits intomainfrom Apr 29, 2024
Merged
Conversation
nnaydenow
approved these changes
Apr 29, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes:
instanceofusage replaced with duck-typingScoping rules:
1. CSS
[ui5-button] { color: red; }instead of
ui5-button { color: red; }2. DOM access
this.shadowRoot.querySelector("[ui5-input]")instead of
this.shadowRoot.querySelector("ui5-input")3. Components used in
.hbsmust be declared independenciesTemplate:
Component class:
dependencies: [ Button, Input ]4.
instanceofcannot be used for components and their base classesIf there are 2 or more instances of the framework on the same HTML page that do not use scoping, some other instance might have declared the class and
instanceofchecks will failInstance A)
Instance B)
In this example the code of "Instance B" will use Tree and Tree item from the runtime A) which means that "ui5-tree-item-custom" will fail all
instanceofchecks.4.1 Solution A - use
getAttributeInstead of:
if (item instanceof Option) {}use:
if (item.hasAttribute("ui5-option") {}4.2 Solution B - use duck-typing
This is the only possible solution if you access the children, and TS must know the class of the duck-typed child.
For examples how to implement duck-typing in TS, see the changes in this PR.