Skip to content

Support @provide with experimental decorators on a property#4200

Merged
rictic merged 3 commits into3.0from
3.0-context-provide-property
Sep 19, 2023
Merged

Support @provide with experimental decorators on a property#4200
rictic merged 3 commits into3.0from
3.0-context-provide-property

Conversation

@rictic
Copy link
Collaborator

@rictic rictic commented Sep 18, 2023

It might feel like this is working at cross purposes to our standard decorators work, because those all require accessors, but I don't think so. With standard decorators we can use the type system to error out if they're used on a property instead of an accessor. With experimental decorators, they sorta work with properties, in that they do provide values and update them, but reading the value back off the field would always give undefined because we were defining it without a getter.

It might feel like this is working at cross purposes to our standard decorators work, because those all require accessors, but I don't think so. With standard decorators we can use the type system to error out if they're used on a property instead of an accessor. With experimental decorators, they sorta work with properties, in that they do provide values and update them, but reading the value back off the field would always give undefined because we were defining it without a getter.
@changeset-bot
Copy link

changeset-bot bot commented Sep 18, 2023

🦋 Changeset detected

Latest commit: 545e76c

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

This PR includes changesets to release 1 package
Name Type
@lit-labs/context Patch

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

@github-actions
Copy link
Contributor

github-actions bot commented Sep 18, 2023

📊 Tachometer Benchmark Results

Summary

nop-update

  • this-change, tip-of-tree, previous-release: unsure 🔍 -9% - +10% (-2.10ms - +2.37ms)
    this-change vs tip-of-tree

render

  • this-change: 93.90ms - 98.92ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -5% - +4% (-1.87ms - +1.30ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -4% - +1% (-2.82ms - +0.54ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -3% - +3% (-1.94ms - +1.99ms)
    this-change vs tip-of-tree

update

  • this-change: 939.18ms - 957.83ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -5% - +4% (-5.20ms - +3.47ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -3% - +2% (-3.77ms - +3.15ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -2% - +2% (-15.47ms - +17.88ms)
    this-change vs tip-of-tree

update-reflect

  • this-change: 904.59ms - 923.05ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -2% - +1% (-22.33ms - +10.70ms)
    this-change vs tip-of-tree

Results

this-change

render

VersionAvg timevs
93.90ms - 98.92ms-

update

VersionAvg timevs
939.18ms - 957.83ms-

update-reflect

VersionAvg timevs
904.59ms - 923.05ms-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
33.60ms - 35.55ms-unsure 🔍
-5% - +4%
-1.87ms - +1.30ms
unsure 🔍
-8% - +1%
-2.79ms - +0.32ms
tip-of-tree
tip-of-tree
33.60ms - 36.11msunsure 🔍
-4% - +5%
-1.30ms - +1.87ms
-unsure 🔍
-7% - +2%
-2.70ms - +0.80ms
previous-release
previous-release
34.59ms - 37.02msunsure 🔍
-1% - +8%
-0.32ms - +2.79ms
unsure 🔍
-2% - +8%
-0.80ms - +2.70ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
93.65ms - 99.43ms-unsure 🔍
-5% - +4%
-5.20ms - +3.47ms
unsure 🔍
-3% - +6%
-2.35ms - +5.77ms
tip-of-tree
tip-of-tree
94.17ms - 100.63msunsure 🔍
-4% - +5%
-3.47ms - +5.20ms
-unsure 🔍
-2% - +7%
-1.74ms - +6.88ms
previous-release
previous-release
91.98ms - 97.69msunsure 🔍
-6% - +2%
-5.77ms - +2.35ms
unsure 🔍
-7% - +2%
-6.88ms - +1.74ms
-

nop-update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
22.39ms - 25.06ms-unsure 🔍
-9% - +10%
-2.10ms - +2.37ms
unsure 🔍
-5% - +11%
-1.23ms - +2.47ms
tip-of-tree
tip-of-tree
21.80ms - 25.38msunsure 🔍
-10% - +9%
-2.37ms - +2.10ms
-unsure 🔍
-7% - +12%
-1.71ms - +2.69ms
previous-release
previous-release
21.82ms - 24.38msunsure 🔍
-10% - +5%
-2.47ms - +1.23ms
unsure 🔍
-11% - +7%
-2.69ms - +1.71ms
-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
60.48ms - 62.41ms-unsure 🔍
-4% - +1%
-2.82ms - +0.54ms
unsure 🔍
-5% - +1%
-3.17ms - +0.60ms
tip-of-tree
tip-of-tree
61.20ms - 63.96msunsure 🔍
-1% - +5%
-0.54ms - +2.82ms
-unsure 🔍
-4% - +3%
-2.27ms - +1.98ms
previous-release
previous-release
61.11ms - 64.34msunsure 🔍
-1% - +5%
-0.60ms - +3.17ms
unsure 🔍
-3% - +4%
-1.98ms - +2.27ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
137.06ms - 142.02ms-unsure 🔍
-3% - +2%
-3.77ms - +3.15ms
unsure 🔍
-4% - +1%
-6.04ms - +1.92ms
tip-of-tree
tip-of-tree
137.44ms - 142.26msunsure 🔍
-2% - +3%
-3.15ms - +3.77ms
-unsure 🔍
-4% - +2%
-5.69ms - +2.18ms
previous-release
previous-release
138.49ms - 144.72msunsure 🔍
-1% - +4%
-1.92ms - +6.04ms
unsure 🔍
-2% - +4%
-2.18ms - +5.69ms
-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
60.22ms - 62.92ms-unsure 🔍
-3% - +3%
-1.94ms - +1.99ms
unsure 🔍
-2% - +4%
-1.20ms - +2.65ms
tip-of-tree
tip-of-tree
60.11ms - 62.97msunsure 🔍
-3% - +3%
-1.99ms - +1.94ms
-unsure 🔍
-2% - +4%
-1.29ms - +2.68ms
previous-release
previous-release
59.47ms - 62.22msunsure 🔍
-4% - +2%
-2.65ms - +1.20ms
unsure 🔍
-4% - +2%
-2.68ms - +1.29ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
968.52ms - 990.60ms-unsure 🔍
-2% - +2%
-15.47ms - +17.88ms
unsure 🔍
-2% - +1%
-16.18ms - +12.32ms
tip-of-tree
tip-of-tree
965.86ms - 990.85msunsure 🔍
-2% - +2%
-17.88ms - +15.47ms
-unsure 🔍
-2% - +1%
-18.54ms - +12.28ms
previous-release
previous-release
972.48ms - 990.50msunsure 🔍
-1% - +2%
-12.32ms - +16.18ms
unsure 🔍
-1% - +2%
-12.28ms - +18.54ms
-

update-reflect

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
960.39ms - 984.51ms-unsure 🔍
-2% - +1%
-22.33ms - +10.70ms
unsure 🔍
-1% - +2%
-12.58ms - +19.28ms
tip-of-tree
tip-of-tree
966.99ms - 989.54msunsure 🔍
-1% - +2%
-10.70ms - +22.33ms
-unsure 🔍
-1% - +3%
-6.18ms - +24.50ms
previous-release
previous-release
958.70ms - 979.51msunsure 🔍
-2% - +1%
-19.28ms - +12.58ms
unsure 🔍
-2% - +1%
-24.50ms - +6.18ms
-

tachometer-reporter-action v2 for Benchmarks

@github-actions
Copy link
Contributor

The size of lit-html.js and lit-core.min.js are as expected.

@lit lit deleted a comment from Marbitch Sep 18, 2023
assert.strictEqual(consumer.value, 500);
assert.strictEqual(consumer2.value, 1000); // one-time consumer still has old value
});

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm getting pretty confused where the tests go in the package these days. This suite didn't previously use any of the context decorators, and the thing you're testing isn't that providers and consumers work, but that the decorator works. This came up for me when I made the std-decorators tests too.

Could we make a decorators-specific test folder?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, done

};
let newDescriptor;
if (descriptor === undefined) {
const symbol = Symbol();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use a more descriptive name like storage or key? Also, Russell added a nice dev-mode switch to @query() where there was a string description for the Symbol like @provide() storage key for ${nameOrContext} for debugging.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Switched to a WeakMap for consistency in this file

Comment on lines +108 to +110
if (oldSetter) {
oldSetter.call(this, value);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (oldSetter) {
oldSetter.call(this, value);
}
oldSetter?.call(this, value);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

this: ReactiveElement & {[symbol]: ValueType},
value: ValueType
) {
controllerMap.get(this)?.setValue(value);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This element will always be in the map by this point, so I don't think we need to optional chaining.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Switched to not-null assertion

Copy link
Collaborator

@justinfagnani justinfagnani left a comment

Choose a reason for hiding this comment

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

nice!

@rictic rictic merged commit 8e737fb into 3.0 Sep 19, 2023
@rictic rictic deleted the 3.0-context-provide-property branch September 19, 2023 17:50
This was referenced Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants