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

Refine API and refactor #132

Merged
merged 66 commits into from
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
94d4e48
Refactor API (wip)
Jul 20, 2018
f8f8862
remove microtask lib in favor of Promise.
Jul 25, 2018
df3c39d
API changes
Aug 3, 2018
dc5d931
Update tests and Readme
Aug 4, 2018
5861e0e
Tweaks based on review.
Aug 4, 2018
8f83306
More review tweaks.
Aug 4, 2018
e18819e
Lint fixes.
Aug 4, 2018
da54543
work around custom elements polyfill issue in tests
Aug 5, 2018
b39b480
Changes based on review
Aug 5, 2018
5ef504e
Documentation updates and type tweaks based on review.
Aug 7, 2018
10fdf29
Allow symbols as properties
Aug 7, 2018
f131d96
Fix property to attributes serialization
Aug 8, 2018
3b5611c
Doc improvements based on review.
Aug 8, 2018
82be06b
Export `PropertyValues` type and fixup usage in tests
Aug 8, 2018
3637c1e
Fixes for IE11
Aug 8, 2018
bbd3267
Adds `firstUpdated`
Aug 8, 2018
3f0315c
Doc tweak based on review.
Aug 8, 2018
85f4cf2
Use new syntax in lit-html rather than old syntax in lit-extended.
Aug 13, 2018
a8d888d
Updates based on review.
Aug 13, 2018
e97392e
Import from core.
Aug 13, 2018
00d9d5c
Updates based on review.
Aug 13, 2018
f2f908d
Ensure properties set in update reflect properly
Aug 14, 2018
8160de8
Add notes about limited Symbol support and skipped test with linked i…
Aug 14, 2018
e4c7d91
Removed getProperty/setProperty
Aug 14, 2018
e6a3c70
Remove unused `_propertyValues`
Aug 14, 2018
b39b979
Support properties defined as symbols
Aug 15, 2018
fed3307
Save flags on element by using bitmask
Aug 15, 2018
5f3cffd
Update package.json
Aug 15, 2018
05ba1e4
Fix IE11 Map support
Aug 22, 2018
4361daf
Update wct package.
Aug 22, 2018
baaf296
Refine properties handling and add optimizations
Aug 22, 2018
f2865de
Fix exports
Aug 22, 2018
d4edcd8
Update tests for `shouldInvalidate` fix
Aug 22, 2018
9f1a709
Remove `BooleanAttribute` and special case `type: Boolean`
Aug 22, 2018
25f4ca6
Adds `invalidateProperty(name, oldValue)`
Aug 22, 2018
9f8e145
Simplify update cycle based on feedback
Aug 22, 2018
59cd15e
Documentation fixes based on feedback.
Aug 22, 2018
bf6da1d
Adds tests for setting properties and attributes in sub-elements.
Aug 23, 2018
f684c63
Fix tests to test updateComplete return value.
Aug 23, 2018
1953a79
Fix typo.
Aug 23, 2018
f3f28b8
Avoid use of Map.keys for IE compat.
Aug 23, 2018
234dff0
Adds `firstRendered` to LitElement and exposes static `render` method.
Aug 23, 2018
24ac381
Removes `finishFirstUpdate` and `finishUpdate`
Aug 23, 2018
13e48e6
Add tests for `@property` directive.
Aug 23, 2018
d708572
Add utility for checking size.
Aug 23, 2018
9a9aced
Documentation fixes based on feedback.
Aug 23, 2018
4bab118
Fix lint errors.
Aug 23, 2018
88a1ad9
Update gitignore and add rollup.config.js
Aug 23, 2018
10edcc6
Don't bother memoizing `observedAttributes` since it's accessed once.
Aug 23, 2018
a447927
IE11 test fixes and slight change to `styleString`
Aug 23, 2018
ec02fd8
Updates based on review.
Aug 23, 2018
b77ee89
Minor doc fixes
Aug 23, 2018
b0c7428
`invalidate` waits for the previous update to complete before advanci…
Aug 23, 2018
9341ae2
Make render abstract
Aug 24, 2018
d3a781b
Rename flag based on review
Aug 24, 2018
af1c542
Renaming based on feedback
Aug 24, 2018
e9d400e
Remove unnecessary check
Aug 24, 2018
bb6d73d
Bump version
Aug 24, 2018
55bc308
Bump lit-html constraint to require 0.11.0-dev.3 (#151)
justinfagnani Aug 24, 2018
b611732
Bump version to 0.6.0-dev.5
justinfagnani Aug 24, 2018
d11ba45
Fix tests on Safari 10
Aug 24, 2018
a85f4bb
Merge branch 'refactor' of https://github.com/PolymerLabs/polymer-lit…
Aug 24, 2018
c312464
Fix tests on Safari 9
Aug 24, 2018
84180cd
Now fix tests on Edge 17
Aug 24, 2018
49cc74c
Update Safari 11 version to test
Aug 24, 2018
ffbfead
Avoid Firefox timeout issue on Travis by testing on Sauce
Aug 24, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 114 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,47 @@

LitElement uses [lit-html](https://github.com/Polymer/lit-html) to render into the
element's [Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can render into light DOM as well, so maybe clarify

and [Polymer's](https://github.com/Polymer/polymer)
[PropertiesMixin](https://github.com/Polymer/polymer/blob/master/lib/mixins/properties-mixin.js)
to help manage element properties and attributes. LitElement reacts to changes in properties
and adds API help manage element properties and attributes. LitElement reacts to changes in properties
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to help manage

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

and renders declaratively using `lit-html`.

* **Setup properties:** LitElement supports observable properties which may trigger an
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the "may" here might be confusing... people might wonder, "but I want it to update!" - "so when doesn't it trigger an update then?"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

update when set. These properties can be written in a few ways:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

written? => added ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


* As class fields with the `@property()` [decorator](https://github.com/tc39/proposal-decorators#decorators),
if you're using a compiler that supports them, like TypeScript or Babel.
* With a static `properties` getter.
* By manually writing getters and setters. This can be useful if tasks should
be performed when a property is set, for example validation. You can call `invalidate()`
in the setter to trigger an update.

Properties can be given an options argument which is an object that describes how to
process the property. This can be done either in the `@property({...})` decorator or in the
object returned from the `properties` getter, e.g. `static get properties { return { foo: {...} }`.

Property options include:

* `attribute`: Describes how and if the property becomes an observed attribute.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if => whether?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

If the value is false, the property is not added to `observedAttributes`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false => false

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ie add back slack `

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

If true or absent, the lowercased property name is observed (e.g. `fooBar` becomes `foobar`).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same with true

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

If a string, the string value is observed (e.g `attribute: 'foo-bar'`).
* `type`: Describes how to serialize and deserialize the attribute to/from a property.
If this value is a function, it is used to deserialize the attribute value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So how does it get serialized in that case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

a the property value. If it's an object, it can have keys for `fromAttribute` and
`toAttribute` where `fromAttribute` is the deserialize function and `toAttribute`
is a serialize function used to set the property to an attribute. If no `toAttribute`
function is provided and `reflect` is set to true, the property value is set
directly to the attribute.
* `reflect`: Describes if the property should reflect to an attribute.
If true, when the property is set, the attribute is set using the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true => true

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

attribute name determined according to the rules for the `attribute`
propety option and the value of the property serialized using the rules from
the `type` property option.
* `shouldInvalidate`: Describes if setting a property should trigger
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this name might be a bit confusing, because as a dev I would think "why shouldn't it invalidade?"

But when I read here it is more understandable that for complex objects equality is much more complex. Maybe I would turn it around and call it isEqual

isEqual: An equality comparisons function used for checking whether the property change does not need re-render. If not present, a strict identity check (=== operator) is used. This function takes the arguments newValue and oldValue and return true if the two values are considered equals, and thus no re-render is needed. This is useful if a property should be considered dirty only if some condition is met, like if a key of an object value changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to leave it as is for now to get some more feedback but will consider changing it.

invalidation and updating. This function takes the `newValue` and `oldValue` and
returns true if invalidation should occur. If not present, a strict identity
check is used. This is useful if a property should be considered dirty only
if some condition is met, like if a key of an object value changes.

* **React to changes:** LitElement reacts to changes in properties and attributes by
asynchronously rendering, ensuring changes are batched. This reduces overhead
and maintains consistent state.
Expand Down Expand Up @@ -68,10 +104,10 @@ and renders declaratively using `lit-html`.
## Minimal Example

1. Create a class that extends `LitElement`.
1. Implement a static `properties` getter that returns the element's properties
(which automatically become observed attributes).
1. Then implement a `_render(props)` method and use the element's
current properties (props) to return a `lit-html` template result to render
1. Use a `@property` decorator to create a property (or implement a static `properties`
getter that returns the element's properties). (which automatically become observed attributes).
1. Then implement a `render()` method and use the element's
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a minimal TypeScript example should be right up top to sell things a little.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

current properties to return a `lit-html` template result to render
into the element. This is the only method that must be implemented by subclasses.

```html
Expand All @@ -81,11 +117,12 @@ into the element. This is the only method that must be implemented by subclasses

class MyElement extends LitElement {

static get properties() { return { mood: String }}
@property({type: String})
mood = 'happy';

_render({mood}) {
render() {
return html`<style> .mood { color: green; } </style>
Web Components are <span class="mood">${mood}</span>!`;
Web Components are <span class="mood">${this.mood}</span>!`;
}

}
Expand All @@ -99,41 +136,71 @@ into the element. This is the only method that must be implemented by subclasses
## API Documentation

See the [source](https://github.com/PolymerLabs/lit-element/blob/master/src/lit-element.ts#L90)
for detailed API info, here are some highlights. Note, the leading underscore
is used to indicate that these methods are
[protected](https://en.wikipedia.org/wiki/Class_(computer_programming)#Member_accessibility);
they are not private and can and should be implemented by subclasses.
These methods generally are called as part of the rendering lifecycle and should
not be called in user code unless otherwise indicated.

* `_createRoot()`: Implement to customize where the
for detailed API info, here are some highlights.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you only list highlights, how is it detailed then? :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed


* `createRenderRoot()` (protected): Implement to customize where the
element's template is rendered by returning an element into which to
render. By default this creates a shadowRoot for the element.
To render into the element's childNodes, return `this`.

* `_firstRendered()`: Called after the element DOM is rendered for the first time.

* `_shouldRender(props, changedProps, prevProps)`: Implement to control if rendering
should occur when property values change or `invalidate` is called.
* `shouldUpdate(changedProperties)` (protected): Implement to control if updating and rendering
should occur when property values change or `invalidate` is called. The `changedProps`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changedProps => changedProperties (you missed that during rename)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

argument is an object with keys for the changed properties pointing to their previous values.
By default, this method always returns true, but this can be customized as
an optimization to avoid rendering work when changes occur which should not be rendered.

* `_render(props)`: Implement to describe the element's DOM using `lit-html`. Ideally,
the `_render` implementation is a pure function using only `props` to describe
the element template. This is the only method that must be implemented by subclasses.

* `_didRender(props, changedProps, prevProps)`: Called after element DOM has been rendered.
Implement to directly control rendered DOM. Typically this is not needed as `lit-html`
can be used in the `_render` method to set properties, attributes, and
event listeners. However, it is sometimes useful for calling methods on
rendered elements, for example focusing an input:
`this.shadowRoot.querySelector('input').focus()`.

* `renderComplete`: Returns a promise which resolves after the element next renders.

* `_requestRender`: Call to request the element to asynchronously re-render regardless
an optimization to avoid updating work when changes occur, which should not be rendered.

* `update()` (protected): This method calls `render()` and then uses `lit-html` to
render the template DOM. Override to customize how the element renders DOM. Note,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to -> in order to

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

during `update()` setting properties does not trigger `invalidate()`, allowing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comma after update()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

property values to be computed and validated.

* `render()` (protected): Implement to describe the element's DOM using `lit-html`. Ideally,
the `render` implementation is a pure function using only the element's current properties
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

link to description of what a pure function is, or describe it shortly

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

to describe the element template. This is the only method that must be implemented by subclasses.
Note, since `render()` is called by `update()` setting properties does not trigger
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comma after update()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

`invalidate()`, allowing property values to be computed and validated.

* `finishUpdate(changedProperties): Promise?` (protected): Called after element DOM has been updated and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

element DOM => the element's DOM ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

before the `updateComplete` promise is resolved. Implement to directly control rendered DOM.
Typically this is not needed as `lit-html` can be used in the `render` method
to set properties, attributes, and event listeners. However, it is sometimes useful
for calling methods on rendered elements, for example focusing an input:
`this.shadowRoot.querySelector('input').focus()`. The `changedProps` argument is an object
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changedProps => changedProperties

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

with keys for the changed properties pointing to their previous values. If this function
returns a `Promise`, it will be *awaited* before resolving the `updateComplete` promise.
Setting properties in `finishUpdate()` does trigger `invalidate()` and blocks
the `updateComplete` promise.

* `finishFirstUpdate(changedProperties): Promise?` (protected) Called after element DOM has been
updated the first time. This method can be useful for capturing references to rendered static
nodes that must be directly acted upon, for example in `finishUpdate`.

* `updateComplete`: Returns a promise which resolves after the element next renders.

* `invalidate`: Call to request the element to asynchronously update regardless
of whether or not any property changes are pending.

## Update Lifecycle

* When the element is first connected or a property is set (e.g. `element.foo = 5`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the nesting here to make this visually more complicated than it is. Also the "thens", "Notes" and other connector words.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrote

and the property's `shouldInvalidate(value, oldValue)` returns true. Then
* `invalidate()` tries to update the element after waiting a [microtask](https://jakearchibald.com/2015/tasks-microtasks-queues-and-schedules/) (at the end
of the event loop, before the next paint). Then
* `shouldUpdate(changedProps)` is called and if this returns true which it
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comma before which

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changedProps again... also below... do a search for that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

does by default:
* `update(changedProps)` is called to update the element.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Note, setting properties inside `update()` will set their values but
will *not* trigger `invalidate()`. This calls
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will after calling super.update() right

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

* `render()` which should return a `lit-html` TemplateResult
(e.g. <code>html\`Hello ${world}\`</code>)
* `finishUpdate(changedProps)` is then called to do post update/render tasks.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Note, setting properties here will trigger `invalidate()` and block
the `updateComplete` promise.
* `updateComplete` promise is resolved only if the element is
not in an invalid state.
* Any code awaiting the element's `updateComplete` promise runs and observes
the element in the updated state.

## Bigger Example

```JavaScript
Expand All @@ -142,25 +209,23 @@ import {LitElement, html} from '@polymer/lit-element';
class MyElement extends LitElement {

// Public property API that triggers re-render (synced with attributes)
static get properties() {
return {
foo: String,
whales: Number
}
}
@property()
foo = 'foo';

@property({type: Number})
whales = 5;

constructor() {
super();
this.foo = 'foo';
this.addEventListener('click', async (e) => {
this.whales++;
await this.renderComplete;
await this.updateComplete;
this.dispatchEvent(new CustomEvent('whales', {detail: {whales: this.whales}}))
});
}

// Render method should return a `TemplateResult` using the provided lit-html `html` tag function
_render({foo, whales}) {
render() {
return html`
<style>
:host {
Expand All @@ -170,8 +235,8 @@ class MyElement extends LitElement {
display: none;
}
</style>
<h4>Foo: ${foo}</h4>
<div>whales: ${'🐳'.repeat(whales)}</div>
<h4>Foo: ${this.foo}</h4>
<div>whales: ${'🐳'.repeat(this.whales)}</div>
<slot></slot>
`;
}
Expand Down
67 changes: 55 additions & 12 deletions demo/lit-element.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,61 @@
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>lit-element demo</title>
<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js"></script>
<script type="module" src = "./ts-element.js"></script>
</head>
<body>
<my-element bar="5" whales="5" foobar="17">Hi</my-element>
<hr>
<ts-element message="Yo" more-info="person"></ts-element>

<script type="module">
import { LitElement, html } from '../lit-element.js';

class Inner extends LitElement {
render() {
return html`Hello world`;
}
}

customElements.define('x-inner', Inner);

class MyElement extends LitElement {

static get properties() {
return {
foo: String,
bar: Number,
whales: Number
nug: {},
zot: {},
foo: {},
bar: {},
whales: {type: Number},
fooBar: {type: {fromAttribute: parseInt, toAttribute: (value) => value + '-attr'}, reflect: true}
}
}

// a custom getter/setter can be created to customize property processing
get zot() { return this.getAttribute('zot'); }

set zot(value) {
this.setAttribute('zot', value);
this.invalidate();
}


constructor() {
super();
this.foo = 'foo';
this.nug = [1, 2, 3];
this.whales = 0;
this.addEventListener('click', async (e) => {
this.whales++;
await this.renderComplete;
await this.updateComplete;
this.dispatchEvent(new CustomEvent('whales', {detail: {whales: this.whales}}))
console.log(this.shadowRoot.querySelector('.count').textContent);
});
}

_firstRendered() {
console.log('first rendered!');
}

_render({foo, bar, whales}) {
render() {
const {foo, bar, whales, fooBar, nug} = this;
return html`
<style>
:host {
Expand All @@ -69,16 +92,36 @@ <h4 on-click="${(e) => console.log(this, e.target)}">Foo: ${foo}, Bar: ${bar}</h
<div class="count">
whales: ${'🐳'.repeat(whales)}
</div>
<ul>
${nug.map(n => html`<li>${n}</li>`)}
</ul>
<x-inner></x-inner>
`;
}

_didRender() {
console.log('didRender!');
update(changedProps) {
super.update(changedProps);
console.log('updated!', changedProps);
}

async finishUpdate(changedProps) {
if (!this._inner) {
this._inner = this.shadowRoot.querySelector('x-inner');
}
await this._inner.updateComplete;
}
}

addEventListener('WebComponentsReady', function() { console.log('wcr - module')})

console.log('defined class');
customElements.define('my-element', MyElement);
console.log('get', customElements.get('my-element'));

(async () => {
const x = document.querySelector('my-element');
await x.updateComplete;
console.log(x.shadowRoot.querySelector('x-inner').shadowRoot.textContent);
})();
</script>
<my-element bar="5" whales="5">Hi</my-element>
</body></html>
Loading