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

[reactive-element] Add queryAssignedElements decorator #2327

Merged
merged 9 commits into from
Dec 7, 2021

Conversation

AndrewJakubowicz
Copy link
Contributor

@AndrewJakubowicz AndrewJakubowicz commented Dec 1, 2021

Fixes: #2292

Adds queryAssignedElements decorator and tests (that similarly match the queryAssignedNodes tests).

This change proposes a new options bag API which lets us avoid needing to use and empty string if targeting an unnamed slot.

Note that there is temporarily an asymmetry between this decorator and queryAssignedNodes which will be addressed with #2332.

How

  • The first commit introduces the new decorator, with tests matching closely what the queryAssignedNodes tests. In fact the fixture is almost identical.
  • Then I add the imports closely following the query-assigned-nodes references in the codebase.
  • Finally I updated the ts-transformer such that it can transform queryAssignedElements into JS.

Testing

Change is tested with unit tests, as well as transformer tests.

@changeset-bot
Copy link

changeset-bot bot commented Dec 1, 2021

🦋 Changeset detected

Latest commit: b3dae4b

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@google-cla google-cla bot added the cla: yes label Dec 1, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Dec 1, 2021

📊 Tachometer Benchmark Results

Summary

nop-update

  • lit-html-kitchen-sink: unsure 🔍 -2% - +1% (-0.49ms - +0.17ms)
    this-change vs tip-of-tree

render

  • lit-element-list: unsure 🔍 -0% - +2% (-0.27ms - +1.22ms)
    this-change vs tip-of-tree
  • lit-html-kitchen-sink: unsure 🔍 -1% - +0% (-0.33ms - +0.04ms)
    this-change vs tip-of-tree
  • lit-html-repeat: unsure 🔍 -6% - +14% (-0.66ms - +1.61ms)
    this-change vs tip-of-tree
  • lit-html-template-heavy: unsure 🔍 -2% - +1% (-0.79ms - +0.77ms)
    this-change vs tip-of-tree
  • reactive-element-list: unsure 🔍 -2% - +1% (-1.05ms - +0.56ms)
    this-change vs tip-of-tree

update

  • lit-element-list: unsure 🔍 -0% - +1% (-2.08ms - +4.47ms)
    this-change vs tip-of-tree
  • lit-html-kitchen-sink: unsure 🔍 -2% - +3% (-1.57ms - +2.21ms)
    this-change vs tip-of-tree
  • lit-html-repeat: unsure 🔍 -1% - +1% (-2.31ms - +2.75ms)
    this-change vs tip-of-tree
  • lit-html-template-heavy: unsure 🔍 -1% - +1% (-1.00ms - +0.84ms)
    this-change vs tip-of-tree
  • reactive-element-list: unsure 🔍 -0% - +1% (-1.94ms - +4.38ms)
    this-change vs tip-of-tree

update-reflect

  • lit-element-list: unsure 🔍 -1% - +0% (-5.88ms - +1.93ms)
    this-change vs tip-of-tree
  • reactive-element-list: unsure 🔍 -1% - +1% (-4.20ms - +4.47ms)
    this-change vs tip-of-tree

Results

lit-element-list

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
70.49ms - 71.77ms-unsure 🔍
-0% - +2%
-0.27ms - +1.22ms
faster ✔
21% - 22%
18.51ms - 20.51ms
tip-of-tree
tip-of-tree
70.28ms - 71.03msunsure 🔍
-2% - +0%
-1.22ms - +0.27ms
-faster ✔
21% - 23%
19.13ms - 20.84ms
previous-release
previous-release
89.87ms - 91.41msslower ❌
26% - 29%
18.51ms - 20.51ms
slower ❌
27% - 30%
19.13ms - 20.84ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
614.62ms - 619.30ms-unsure 🔍
-0% - +1%
-2.08ms - +4.47ms
faster ✔
7% - 9%
49.04ms - 57.18ms
tip-of-tree
tip-of-tree
613.47ms - 618.06msunsure 🔍
-1% - +0%
-4.47ms - +2.08ms
-faster ✔
8% - 9%
50.26ms - 58.35ms
previous-release
previous-release
666.74ms - 673.40msslower ❌
8% - 9%
49.04ms - 57.18ms
slower ❌
8% - 9%
50.26ms - 58.35ms
-

update-reflect

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
673.77ms - 679.05ms-unsure 🔍
-1% - +0%
-5.88ms - +1.93ms
faster ✔
3% - 4%
19.06ms - 26.76ms
tip-of-tree
tip-of-tree
675.50ms - 681.27msunsure 🔍
-0% - +1%
-1.93ms - +5.88ms
-faster ✔
2% - 4%
16.91ms - 24.95ms
previous-release
previous-release
696.52ms - 702.12msslower ❌
3% - 4%
19.06ms - 26.76ms
slower ❌
2% - 4%
16.91ms - 24.95ms
-
lit-html-kitchen-sink

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
28.41ms - 28.67ms-unsure 🔍
-1% - +0%
-0.33ms - +0.04ms
faster ✔
14% - 16%
4.57ms - 5.48ms
tip-of-tree
tip-of-tree
28.55ms - 28.81msunsure 🔍
-0% - +1%
-0.04ms - +0.33ms
-faster ✔
13% - 16%
4.42ms - 5.34ms
previous-release
previous-release
33.12ms - 34.00msslower ❌
16% - 19%
4.57ms - 5.48ms
slower ❌
15% - 19%
4.42ms - 5.34ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
75.91ms - 79.21ms-unsure 🔍
-2% - +3%
-1.57ms - +2.21ms
faster ✔
2% - 7%
1.34ms - 5.90ms
tip-of-tree
tip-of-tree
76.32ms - 78.15msunsure 🔍
-3% - +2%
-2.21ms - +1.57ms
-faster ✔
3% - 7%
2.12ms - 5.76ms
previous-release
previous-release
79.61ms - 82.74msslower ❌
2% - 8%
1.34ms - 5.90ms
slower ❌
3% - 7%
2.12ms - 5.76ms
-

nop-update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
24.09ms - 24.47ms-unsure 🔍
-2% - +1%
-0.49ms - +0.17ms
faster ✔
11% - 16%
3.08ms - 4.65ms
tip-of-tree
tip-of-tree
24.17ms - 24.71msunsure 🔍
-1% - +2%
-0.17ms - +0.49ms
-faster ✔
11% - 16%
2.90ms - 4.51ms
previous-release
previous-release
27.38ms - 28.91msslower ❌
13% - 19%
3.08ms - 4.65ms
slower ❌
12% - 19%
2.90ms - 4.51ms
-
lit-html-repeat

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
10.84ms - 13.08ms-unsure 🔍
-6% - +14%
-0.66ms - +1.61ms
unsure 🔍
-13% - +5%
-1.57ms - +0.68ms
tip-of-tree
tip-of-tree
11.34ms - 11.63msunsure 🔍
-13% - +5%
-1.61ms - +0.66ms
-faster ✔
6% - 9%
0.77ms - 1.07ms
previous-release
previous-release
12.37ms - 12.45msunsure 🔍
-6% - +13%
-0.68ms - +1.57ms
slower ❌
7% - 9%
0.77ms - 1.07ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
277.51ms - 281.14ms-unsure 🔍
-1% - +1%
-2.31ms - +2.75ms
faster ✔
28% - 30%
111.24ms - 116.98ms
tip-of-tree
tip-of-tree
277.34ms - 280.86msunsure 🔍
-1% - +1%
-2.75ms - +2.31ms
-faster ✔
28% - 30%
111.50ms - 117.17ms
previous-release
previous-release
391.21ms - 395.65msslower ❌
40% - 42%
111.24ms - 116.98ms
slower ❌
40% - 42%
111.50ms - 117.17ms
-
lit-html-template-heavy

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
51.14ms - 52.48ms-unsure 🔍
-2% - +1%
-0.79ms - +0.77ms
faster ✔
14% - 17%
8.81ms - 10.77ms
tip-of-tree
tip-of-tree
51.41ms - 52.23msunsure 🔍
-1% - +2%
-0.77ms - +0.79ms
-faster ✔
15% - 17%
8.95ms - 10.61ms
previous-release
previous-release
60.88ms - 62.32msslower ❌
17% - 21%
8.81ms - 10.77ms
slower ❌
17% - 21%
8.95ms - 10.61ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
107.47ms - 108.84ms-unsure 🔍
-1% - +1%
-1.00ms - +0.84ms
faster ✔
12% - 14%
14.86ms - 17.26ms
tip-of-tree
tip-of-tree
107.62ms - 108.85msunsure 🔍
-1% - +1%
-0.84ms - +1.00ms
-faster ✔
12% - 14%
14.82ms - 17.14ms
previous-release
previous-release
123.24ms - 125.20msslower ❌
14% - 16%
14.86ms - 17.26ms
slower ❌
14% - 16%
14.82ms - 17.14ms
-
reactive-element-list

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
51.40ms - 52.48ms-unsure 🔍
-2% - +1%
-1.05ms - +0.56ms
unsure 🔍
-1% - +2%
-0.27ms - +1.22ms
tip-of-tree
tip-of-tree
51.59ms - 52.77msunsure 🔍
-1% - +2%
-0.56ms - +1.05ms
-unsure 🔍
-0% - +3%
-0.06ms - +1.50ms
previous-release
previous-release
50.95ms - 51.97msunsure 🔍
-2% - +1%
-1.22ms - +0.27ms
unsure 🔍
-3% - +0%
-1.50ms - +0.06ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
622.68ms - 627.10ms-unsure 🔍
-0% - +1%
-1.94ms - +4.38ms
unsure 🔍
-0% - +1%
-2.68ms - +3.72ms
tip-of-tree
tip-of-tree
621.41ms - 625.92msunsure 🔍
-1% - +0%
-4.38ms - +1.94ms
-unsure 🔍
-1% - +0%
-3.94ms - +2.54ms
previous-release
previous-release
622.05ms - 626.68msunsure 🔍
-1% - +0%
-3.72ms - +2.68ms
unsure 🔍
-0% - +1%
-2.54ms - +3.94ms
-

update-reflect

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
700.75ms - 707.64ms-unsure 🔍
-1% - +1%
-4.20ms - +4.47ms
unsure 🔍
-1% - +1%
-5.26ms - +4.36ms
tip-of-tree
tip-of-tree
701.43ms - 706.69msunsure 🔍
-1% - +1%
-4.47ms - +4.20ms
-unsure 🔍
-1% - +1%
-4.85ms - +3.69ms
previous-release
previous-release
701.28ms - 708.00msunsure 🔍
-1% - +1%
-4.36ms - +5.26ms
unsure 🔍
-1% - +1%
-3.69ms - +4.85ms
-

tachometer-reporter-action v2 for Benchmarks

@AndrewJakubowicz AndrewJakubowicz force-pushed the feat-query-assigned-elements branch 4 times, most recently from 9b8224b to d5d4506 Compare December 2, 2021 17:45
@AndrewJakubowicz AndrewJakubowicz changed the title [Feature] Add queryAssignedElements decorator [reactive-element] Add queryAssignedElements decorator Dec 2, 2021
@AndrewJakubowicz AndrewJakubowicz marked this pull request as ready for review December 2, 2021 19:27
if (
propAssignment &&
ts.isPropertyAssignment(propAssignment) &&
ts.isStringLiteral(propAssignment.initializer)
Copy link
Member

Choose a reason for hiding this comment

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

Should probably throw if it's not a string literal, because it could also be a variable and we'd silently ignore that here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done thank you!

Copy link
Member

Choose a reason for hiding this comment

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

Actually just occured to me that selector could be used as-is whatever kind of node it is, since it just goes directly into the filter arguments, right?

And you could maybe also handle slot being an identifier or whatever too by generating `slot[name=${node}]` in the case that it's not a string?

@AndrewJakubowicz AndrewJakubowicz force-pushed the feat-query-assigned-elements branch 3 times, most recently from 575b2e7 to 51b8df7 Compare December 2, 2021 22:04
@AndrewJakubowicz AndrewJakubowicz force-pushed the feat-query-assigned-elements branch 3 times, most recently from 4097a4e to 07417c2 Compare December 2, 2021 22:40
@AndrewJakubowicz AndrewJakubowicz force-pushed the feat-query-assigned-elements branch 2 times, most recently from 34fb99c to 6149cbf Compare December 3, 2021 00:55
@AndrewJakubowicz AndrewJakubowicz force-pushed the feat-query-assigned-elements branch 2 times, most recently from 367cc64 to 863ecc0 Compare December 3, 2021 01:27
@AndrewJakubowicz
Copy link
Contributor Author

Tests are passing. The only tests failing is something to do with Sauce not connecting:

ests: Error: 3 Dec 01:36:24 - Sauce Connect could not establish a connection.
tests: 3 Dec 01:36:24 - Please check your firewall and proxy settings.
tests: 3 Dec 01:36:24 - Goodbye.
tests:     at Socket.<anonymous> (/home/runner/work/lit/lit/packages/tests/node_modules/saucelabs/build/index.js:322:25)
tests:     at Socket.emit (events.js:400:28)
tests:     at Socket.emit (domain.js:475:12)
tests:     at addChunk (internal/streams/readable.js:293:12)
tests:     at readableAddChunk (internal/streams/readable.js:267:9)
tests:     at Socket.Readable.push (internal/streams/readable.js:206:10)
tests:     at Pipe.onStreamRead (internal/stream_base_commons.js:188:23)

I think this is unrelated to my changes.

Copy link
Member

@aomarks aomarks left a comment

Choose a reason for hiding this comment

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

This is great! Awesome to do get the transformer code in too.

.changeset/famous-feet-kneel.md Show resolved Hide resolved
if (
propAssignment &&
ts.isPropertyAssignment(propAssignment) &&
ts.isStringLiteral(propAssignment.initializer)
Copy link
Member

Choose a reason for hiding this comment

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

Actually just occured to me that selector could be used as-is whatever kind of node it is, since it just goes directly into the filter arguments, right?

And you could maybe also handle slot being an identifier or whatever too by generating `slot[name=${node}]` in the case that it's not a string?

…signedElements

Add references to the new internal decorator across the monorepo packages.
`slot` instead of `slotName`.
Fix up copy pasted tests such that they are more modern, remove unused pieces.
Update the transformer tests.
In this change made the transformer far more flexible. It no longer
forces string literal arguments, and instead utilizes template strings
to handle arbitrary expressions or identifiers.
Copy link
Member

@aomarks aomarks left a comment

Choose a reason for hiding this comment

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

💯

@justinfagnani justinfagnani added this to the Lit 2.1 milestone Dec 7, 2021
Some documentation updates and a missed optional chaining.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[lit/reactive-element] Add @queryAssignedElements() decorator
3 participants