[labs/task] Add pluggable task args equality functions#4013
[labs/task] Add pluggable task args equality functions#4013justinfagnani merged 7 commits intomainfrom
Conversation
🦋 Changeset detectedLatest commit: 313019f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
📊 Tachometer Benchmark ResultsSummarynop-update
render
update
update-reflect
Resultslit-element-list
render
update
update-reflect
lit-html-kitchen-sink
render
update
nop-update
lit-html-repeat
render
update
lit-html-template-heavy
render
update
reactive-element-list
render
update
update-reflect
this-change
render
update
update-reflect
this-change, tip-of-tree, previous-release
render
update
nop-update
this-change, tip-of-tree, previous-release
render
update
this-change, tip-of-tree, previous-release
render
update
update-reflect
|
packages/labs/task/src/task.ts
Outdated
| const {keys: objectKeys} = Object; | ||
| const {isArray} = Array; | ||
|
|
||
| export const deepEquals = (a: unknown, b: unknown): boolean => { |
There was a problem hiding this comment.
Deep equality checks require a number of opinionated pieces. Do we want to maintain this? Do we want to ship these bytes, or are we assuming production builds are tree shaked?
There was a problem hiding this comment.
Yes they do, but... it's quite hard to find a minimally good deep equals, especially that's shipped as JS modules. I think including some basic one is just good DX.
I do need to document the opinions here:
- Object.is for primitives
- Constructor check
- Arrays
valueOf()andtoString()checks- Map and Set (whichever way we go)
- Own property requirement for objects
- Cycles (currently we don't detect them and just iloop, which a lot of libraries do, but some don't)
There was a problem hiding this comment.
WDYT about putting this in its own module?
packages/labs/task/src/task.ts
Outdated
| const {keys: objectKeys} = Object; | ||
| const {isArray} = Array; | ||
|
|
||
| export const deepEquals = (a: unknown, b: unknown): boolean => { |
There was a problem hiding this comment.
WDYT about putting this in its own module?
| // TODO: the name of this function is confusing. It doesn't wait for the task | ||
| // to complete. It just waits a rAF. That's why it can be used to check that | ||
| // a task is pending. | ||
| const tasksUpdateComplete = nextFrame; |
There was a problem hiding this comment.
Good point. I'd consider dropping this in favor of just directly using nextFrame
|
I'm a little stuck on the tests right now. Browser can't seem to load the new deep-equals test module. But I ran both the dev and prod tests in a live Sauce session and they all load and pass. The GitHub actions logs are giving nothing more than a "failed to load module" error. No browser logs that say what the specific error is. edit: I read the logs wrong and this is happening in all browsers. This made me look for a Wireit, package.json, or Rollup config error for the new entry-point, but I can't see one yet. |
Fixes: #3142
shouldRun()andperformTask()protected methodsshallowArrayEquals,deepArrayEquals, anddeepEqualsfunctionsThe
deepEquals()is inspired by fast-deep-equals, but rewritten to use modern JS,Object.is(), and have a different ordering of cases that should better match expected data (Dates would be more likely than RegExps). I did not yet include Map and Set comparison. I didn't find a nice deep equals package to depend on that fit our needs.Talking to @rictic I think we may also want to generalize args to just "data" and not assume it's array, but this can be a step towards that with the array-assuming equality functions.