-
-
Notifications
You must be signed in to change notification settings - Fork 78
Split into CSSStyleDeclaration and CSSStyleProperties #244
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
base: main
Are you sure you want to change the base?
Conversation
3ae525e
to
ab291f8
Compare
1a3321e
to
46b08ca
Compare
Back to draft, will enable after jsdom@27 issues are addressed. |
Workaround for jsdom/jsdom#3939
8c0a95d
to
e115115
Compare
Unit test for jsdom/jsdom#3940
Ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tested this with a local fork of jsdom yet? It's probably best to merge and release only once we know it works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain the purpose of this file in a longer comment at the top of it? I'm curious about questions like:
- Why is lru-cache alone not good enough?
- What is the deal with null cache items? How do they differ from storing "null", or not storing anything at all?
- Why do we need a custom JSON stringification instead of using the default? Why is JSON involved at all?
constructor(onChangeCallback, opt = {}) { | ||
// Make constructor and internals non-enumerable. | ||
constructor(globalObject = globalThis, opt = {}) { | ||
// Make internals non-enumerable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This extra work should no longer be necessary in the new architecture. We can just set properties normally.
this._readonly = true; | ||
} else if (context.nodeType === 1 && Object.hasOwn(context, "style")) { | ||
this._global = context.ownerDocument.defaultView; | ||
if (context.nodeType === 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please declare a constant for this at the top of the file.
} | ||
if (typeof onChangeCallback === "function") { | ||
this._onChange = onChangeCallback; | ||
if (typeof opt.onChange === "function") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably best to assume such a function is always passed.
} | ||
|
||
// Non-standard | ||
setOptions(opt = {}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a comment for what this will be used for? (In general, changing options after creation seems unusual, so documenting it is good.)
} | ||
|
||
const propertyNamesJSON = JSON.stringify(Array.from(propertyNames), undefined, 2); | ||
const propertyNamesJSON = JSON.stringify([...propertyNames], null, 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: prefer undefined
to null
for triggering defaults.
const propertyNamesJSON = JSON.stringify([...propertyNames], null, 2); | |
const propertyNamesJSON = JSON.stringify([...propertyNames], undefined, 2); |
); | ||
const dateToday = new Date(); | ||
const [dateTodayFormatted] = dateToday.toISOString().split("T"); | ||
const [dateTodayFormatted] = new Date().toISOString().split("T"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I find this part of JavaScript very confusing so I prefer parentheses.
const [dateTodayFormatted] = new Date().toISOString().split("T"); | |
const [dateTodayFormatted] = (new Date()).toISOString().split("T"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this file is separate from CSSStyleProperties.test.js
? Maybe one or both of them should get a comment, if the separation is intentional?
Part of #235
Rebased #243
Fixes #242, fixes #247, fixes jsdom/jsdom#3939, fixes jsdom/jsdom#3940
I'll include wpt style tests later (when I submit a PR to jsdom to update the cssstyle)
Spec: https://drafts.csswg.org/cssom/#the-cssstyledeclaration-interface