Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@justinfagnani
Copy link
Collaborator

@justinfagnani justinfagnani commented Dec 4, 2021

These helpers are simple functions, not directives, that help make a template read a bit more declaratively when containing conditionals and loops. They're not strictly necessary, but we've found a number of users ask for them or write their own.

Adds:

  • when(): sugar for ternaries. Especially nice when there's no else clause
  • map(): Evaluate a function of items in an iterable. Stylistically more "declarative" and works with iterables.
  • join(): Interleaves the items of an iterable with a joiner value or result of calling a joiner function.
  • range(): Returns an iterable that contains number in a range. Useful when combined with map().

@changeset-bot
Copy link

changeset-bot bot commented Dec 4, 2021

🦋 Changeset detected

Latest commit: f6003ea

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 4, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Dec 4, 2021

📊 Tachometer Benchmark Results

Summary

nop-update

  • lit-html-kitchen-sink: unsure 🔍 -2% - +5% (-0.47ms - +1.15ms)
    this-change vs tip-of-tree

render

  • lit-element-list: unsure 🔍 -2% - +1% (-1.39ms - +0.83ms)
    this-change vs tip-of-tree
  • lit-html-kitchen-sink: unsure 🔍 -1% - +0% (-0.24ms - +0.07ms)
    this-change vs tip-of-tree
  • lit-html-repeat: unsure 🔍 -3% - +0% (-0.29ms - +0.05ms)
    this-change vs tip-of-tree
  • lit-html-template-heavy: unsure 🔍 -1% - +1% (-0.37ms - +0.71ms)
    this-change vs tip-of-tree
  • reactive-element-list: unsure 🔍 -2% - +1% (-0.86ms - +0.54ms)
    this-change vs tip-of-tree

update

  • lit-element-list: unsure 🔍 -0% - +1% (-2.88ms - +4.52ms)
    this-change vs tip-of-tree
  • lit-html-kitchen-sink: unsure 🔍 -3% - +1% (-2.21ms - +1.13ms)
    this-change vs tip-of-tree
  • lit-html-repeat: unsure 🔍 -1% - +1% (-1.69ms - +4.07ms)
    this-change vs tip-of-tree
  • lit-html-template-heavy: unsure 🔍 -1% - +1% (-0.62ms - +0.97ms)
    this-change vs tip-of-tree
  • reactive-element-list: unsure 🔍 -1% - +0% (-4.11ms - +1.13ms)
    this-change vs tip-of-tree

update-reflect

  • lit-element-list: unsure 🔍 -0% - +1% (-3.20ms - +6.24ms)
    this-change vs tip-of-tree
  • reactive-element-list: unsure 🔍 -1% - +0% (-6.19ms - +3.28ms)
    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.94ms - 72.19ms-unsure 🔍
-2% - +1%
-1.39ms - +0.83ms
faster ✔
20% - 23%
18.48ms - 20.94ms
tip-of-tree
tip-of-tree
70.92ms - 72.76msunsure 🔍
-1% - +2%
-0.83ms - +1.39ms
-faster ✔
20% - 23%
18.03ms - 20.84ms
previous-release
previous-release
90.22ms - 92.33msslower ❌
26% - 29%
18.48ms - 20.94ms
slower ❌
25% - 29%
18.03ms - 20.84ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
618.82ms - 624.69ms-unsure 🔍
-0% - +1%
-2.88ms - +4.52ms
faster ✔
7% - 8%
47.40ms - 56.35ms
tip-of-tree
tip-of-tree
618.69ms - 623.19msunsure 🔍
-1% - +0%
-4.52ms - +2.88ms
-faster ✔
7% - 8%
48.63ms - 56.75ms
previous-release
previous-release
670.25ms - 677.01msslower ❌
8% - 9%
47.40ms - 56.35ms
slower ❌
8% - 9%
48.63ms - 56.75ms
-

update-reflect

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
680.53ms - 688.63ms-unsure 🔍
-0% - +1%
-3.20ms - +6.24ms
faster ✔
2% - 4%
15.61ms - 26.07ms
tip-of-tree
tip-of-tree
680.64ms - 685.49msunsure 🔍
-1% - +0%
-6.24ms - +3.20ms
-faster ✔
3% - 4%
18.25ms - 26.46ms
previous-release
previous-release
702.11ms - 708.73msslower ❌
2% - 4%
15.61ms - 26.07ms
slower ❌
3% - 4%
18.25ms - 26.46ms
-
lit-html-kitchen-sink

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
28.43ms - 28.61ms-unsure 🔍
-1% - +0%
-0.24ms - +0.07ms
faster ✔
15% - 18%
5.09ms - 6.45ms
tip-of-tree
tip-of-tree
28.48ms - 28.73msunsure 🔍
-0% - +1%
-0.07ms - +0.24ms
-faster ✔
15% - 18%
5.00ms - 6.37ms
previous-release
previous-release
33.61ms - 34.96msslower ❌
18% - 23%
5.09ms - 6.45ms
slower ❌
17% - 22%
5.00ms - 6.37ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
76.59ms - 79.21ms-unsure 🔍
-3% - +1%
-2.21ms - +1.13ms
faster ✔
2% - 8%
1.19ms - 6.63ms
tip-of-tree
tip-of-tree
77.40ms - 79.46msunsure 🔍
-1% - +3%
-1.13ms - +2.21ms
-faster ✔
1% - 7%
0.78ms - 5.97ms
previous-release
previous-release
79.43ms - 84.19msslower ❌
1% - 9%
1.19ms - 6.63ms
slower ❌
1% - 8%
0.78ms - 5.97ms
-

nop-update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
24.97ms - 26.53ms-unsure 🔍
-2% - +5%
-0.47ms - +1.15ms
faster ✔
9% - 15%
2.61ms - 4.36ms
tip-of-tree
tip-of-tree
25.19ms - 25.64msunsure 🔍
-4% - +2%
-1.15ms - +0.47ms
-faster ✔
12% - 14%
3.37ms - 4.28ms
previous-release
previous-release
28.84ms - 29.63msslower ❌
10% - 17%
2.61ms - 4.36ms
slower ❌
13% - 17%
3.37ms - 4.28ms
-
lit-html-repeat

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
11.42ms - 11.66ms-unsure 🔍
-3% - +0%
-0.29ms - +0.05ms
faster ✔
7% - 9%
0.89ms - 1.14ms
tip-of-tree
tip-of-tree
11.53ms - 11.78msunsure 🔍
-0% - +3%
-0.05ms - +0.29ms
-faster ✔
6% - 8%
0.76ms - 1.03ms
previous-release
previous-release
12.51ms - 12.60msslower ❌
8% - 10%
0.89ms - 1.14ms
slower ❌
6% - 9%
0.76ms - 1.03ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
276.06ms - 280.79ms-unsure 🔍
-1% - +1%
-1.69ms - +4.07ms
faster ✔
28% - 30%
110.47ms - 117.01ms
tip-of-tree
tip-of-tree
275.59ms - 278.88msunsure 🔍
-1% - +1%
-4.07ms - +1.69ms
-faster ✔
29% - 30%
112.13ms - 117.73ms
previous-release
previous-release
389.91ms - 394.43msslower ❌
39% - 42%
110.47ms - 117.01ms
slower ❌
40% - 43%
112.13ms - 117.73ms
-
lit-html-template-heavy

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
51.69ms - 52.34ms-unsure 🔍
-1% - +1%
-0.37ms - +0.71ms
faster ✔
15% - 18%
9.31ms - 11.03ms
tip-of-tree
tip-of-tree
51.41ms - 52.28msunsure 🔍
-1% - +1%
-0.71ms - +0.37ms
-faster ✔
15% - 18%
9.44ms - 11.25ms
previous-release
previous-release
61.39ms - 62.98msslower ❌
18% - 21%
9.31ms - 11.03ms
slower ❌
18% - 22%
9.44ms - 11.25ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
109.77ms - 110.86ms-unsure 🔍
-1% - +1%
-0.62ms - +0.97ms
faster ✔
12% - 13%
14.42ms - 16.61ms
tip-of-tree
tip-of-tree
109.56ms - 110.71msunsure 🔍
-1% - +1%
-0.97ms - +0.62ms
-faster ✔
12% - 13%
14.58ms - 16.80ms
previous-release
previous-release
124.88ms - 126.77msslower ❌
13% - 15%
14.42ms - 16.61ms
slower ❌
13% - 15%
14.58ms - 16.80ms
-
reactive-element-list

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
51.69ms - 52.57ms-unsure 🔍
-2% - +1%
-0.86ms - +0.54ms
unsure 🔍
-2% - +1%
-0.87ms - +0.58ms
tip-of-tree
tip-of-tree
51.75ms - 52.83msunsure 🔍
-1% - +2%
-0.54ms - +0.86ms
-unsure 🔍
-1% - +2%
-0.77ms - +0.80ms
previous-release
previous-release
51.71ms - 52.84msunsure 🔍
-1% - +2%
-0.58ms - +0.87ms
unsure 🔍
-2% - +1%
-0.80ms - +0.77ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
625.07ms - 628.28ms-unsure 🔍
-1% - +0%
-4.11ms - +1.13ms
unsure 🔍
-0% - +0%
-2.83ms - +2.18ms
tip-of-tree
tip-of-tree
626.09ms - 630.23msunsure 🔍
-0% - +1%
-1.13ms - +4.11ms
-unsure 🔍
-0% - +1%
-1.66ms - +3.99ms
previous-release
previous-release
625.08ms - 628.92msunsure 🔍
-0% - +0%
-2.18ms - +2.83ms
unsure 🔍
-1% - +0%
-3.99ms - +1.66ms
-

update-reflect

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
707.71ms - 714.77ms-unsure 🔍
-1% - +0%
-6.19ms - +3.28ms
unsure 🔍
-1% - +1%
-5.31ms - +4.03ms
tip-of-tree
tip-of-tree
709.53ms - 715.86msunsure 🔍
-0% - +1%
-3.28ms - +6.19ms
-unsure 🔍
-1% - +1%
-3.59ms - +5.22ms
previous-release
previous-release
708.82ms - 714.94msunsure 🔍
-1% - +1%
-4.03ms - +5.31ms
unsure 🔍
-1% - +1%
-5.22ms - +3.59ms
-

tachometer-reporter-action v2 for Benchmarks

@justinfagnani justinfagnani requested a review from aomarks December 6, 2021 22:40
@justinfagnani justinfagnani marked this pull request as ready for review December 6, 2021 22:40
@justinfagnani justinfagnani added this to the Lit 2.1 milestone Dec 6, 2021
@justinfagnani justinfagnani changed the title Add when, map, join, and range template helpers. [lit-html] Add when, map, join, and range template helpers. Dec 7, 2021
@aomarks
Copy link
Member

aomarks commented Dec 7, 2021

We had this discussion offline, writing up here:

From a usage perspective, these new helpers seem to be in the same category as directives. The difference is really just an implementation detail -- that these ones don't need to use the Directive class.

E.g. it could be difficult for users to remember that repeat is imported from directives/repeat.js, but join is imported from helpers.js. To users who aren't familiar with the implementations, there would probably be no obvious reason why we've organized them this way.

Some options:

  1. Keep the distinction. Helpers implemented with Directive are imported from directives/<directive>.js, otherwise from helpers.js (except for ifDefined which doesn't use Directive but is already under directives/).

  2. Grant these new helpers the "directive" title, even though they technically aren't. Synecdoches are ok sometimes?

  3. Move existing directives and these new helpers into a new helpers/ or similar folder, and add re-exports to make non-breaking. "Helpers" becomes our broad term for template-utility-functions, and "directives" are for the specific type of helper that needs deeper control into how Lit renders.

@graynorton
Copy link
Contributor

I like this option:

  1. Move existing directives and these new helpers into a new helpers/ or similar folder, and add re-exports to make non-breaking. "Helpers" becomes our broad term for template-utility-functions, and "directives" are for the specific type of helper that needs deeper control into how Lit renders.

@justinfagnani
Copy link
Collaborator Author

Moved the helpers into directives/

@justinfagnani justinfagnani requested a review from aomarks December 7, 2021 18:02
@justinfagnani justinfagnani changed the title [lit-html] Add when, map, join, and range template helpers. [lit-html] Add when, map, join, and range directives. Dec 7, 2021
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.

LGTM!

@justinfagnani
Copy link
Collaborator Author

@kevinpschaaf are you good with this now?

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.

4 participants