Re: [csswg-drafts] [css-nesting-1] Consider using ObservableArray<CSSRule> instead of CSSRuleList (#8350)

The CSS Working Group just discussed `[css-nesting-1] Consider using ObservableArray<CSSRule> instead of CSSRuleList`, and agreed to the following:

* `RESOLVED: Redefine CSSRuleList as ObservableArray`

<details><summary>The full IRC log of that discussion</summary>
&lt;fantasai> TabAtkins: Domenic raised the fact that CSSStyleRule has a new ??<br>
&lt;fantasai> ... it's the weird legacy CSSRuleList<br>
&lt;fantasai> ... which is a weird old DOM interface that pretends to be a list, but very awkwardly<br>
&lt;fantasai> ... suggested to use ObservableArray, which can reproduce behavior<br>
&lt;fantasai> ... and we can subclass it stuff<br>
&lt;fantasai> TabAtkins: I would like to be good, but I would like to be consistent<br>
&lt;fantasai> ... so if we do this, we should do it by creating a subclass that adds all the legacy interfaces<br>
&lt;fantasai> ... and do it throughout the CSSOM<br>
&lt;fantasai> astearns: So on other places where we use CSSRuleList, that would result in some extra things that you currently can't do with those objects?<br>
&lt;fantasai> ... so we would need tests for all this<br>
&lt;fantasai> TabAtkins: Yes, all of the array methods, which don't exist on CSSRuleList, would start showing up there<br>
&lt;fantasai> ... need tests that we're not doing the weird things<br>
&lt;fremy> q+<br>
&lt;fantasai> astearns: [missed]<br>
&lt;emeyer> fantasai: Are you oing to redefine CSS rule list or something else?<br>
&lt;fantasai> TabAtkins: redefining CSSRuleLIst<br>
&lt;emeyer> s/oing/going/<br>
&lt;fantasai> ... I will make it a subclass of ObservableArray<br>
&lt;fantasai> sgtm<br>
&lt;emilio> q+<br>
&lt;astearns> ack fantasai<br>
&lt;astearns> ack fremy<br>
&lt;fantasai> fremy: Mainly had a question about CSSRuleLIst, right now can you modify it?<br>
&lt;fantasai> ... I thought it was a readonly array<br>
&lt;fantasai> ... ObservableArray is read-write<br>
&lt;fantasai> TabAtkins: That's something that we can define<br>
&lt;fantasai> ... make sure that the readonly bits throw on the setting they're deleting<br>
&lt;fantasai> fremy: Why Observable if it's readonly?<br>
&lt;fantasai> TabAtkins: ObservableArray is how we should do arrays generally<br>
&lt;fantasai> ... plain array supposed to be static, not invisibly modified by the browser<br>
&lt;fantasai> ... ObservableArray allows modification underneath<br>
&lt;fantasai> fremy: ah, ok<br>
&lt;fantasai> TabAtkins: browser doing Observing, which can go both ways<br>
&lt;plinss> q+<br>
&lt;fantasai> heycam: this might be first one where API would allow script to modify it<br>
&lt;fantasai> TabAtkins: possibly? But that would be by luck<br>
&lt;fantasai> ... a script-modifiable ObservableArray is reason we defined ObservableArray rather than frozen list<br>
&lt;fantasai> heycam: Does that have methods that can modify the array?<br>
&lt;fantasai> TabAtkins: ?? is that array<br>
&lt;fantasai> ... it is an Array exotic object, so looks like an array to author script code<br>
&lt;fantasai> heycam: so you can splice it etc?<br>
&lt;astearns> ack emilio<br>
&lt;fantasai> emilio: Plan is to make it readonly?<br>
&lt;fantasai> TabAtkins: keep the current readonly-ness<br>
&lt;fantasai> ... except now it will get the array modern methods<br>
&lt;fantasai> ... but it will continue to be readonly<br>
&lt;fantasai> emilio: so Something.cssRules.push would throw?<br>
&lt;fantasai> TabAtkins: yes. WebIDL has you specify the array modification behavior using a set/delete algorithm<br>
&lt;fantasai> ... and that gets called by all the mutation methods underneath<br>
&lt;fantasai> ... so if you try to modify, it'll throw<br>
&lt;fantasai> emilio: then I'm not opposed, but, it feels weird to expose all the mutating methods if you can't mutate it?<br>
&lt;fantasai> ... if you feel it's better, sure. Just want to make sure we're not making the OM more mutable<br>
&lt;matthieudubet> q+<br>
&lt;fantasai> TabAtkins: don't intend to change mutability, just expose more modern interfaces<br>
&lt;astearns> ack fantasai<br>
&lt;emeyer> fantasai: Why isn’t there an equivalent observable array that’s designed to be read-only?<br>
&lt;fantasai> TabAtkins: behavior to make readonly is trivial, just define set/delete to throw<br>
&lt;fantasai> TabAtkins: This is an intended use case<br>
&lt;fantasai> emilio: I think it will confuse authors<br>
&lt;fantasai> ... but we'll see<br>
&lt;fantasai> ... not like you can construct CSSRuleList, so maybe not too weird<br>
&lt;astearns> ack plinss<br>
&lt;fantasai> plinss: I'm in favor, just two things to confirm<br>
&lt;fantasai> ... we get iterators etc?<br>
&lt;fantasai> TabAtkins: yes<br>
&lt;fantasai> plinss: perfect<br>
&lt;fantasai> plinss: my other question, are there other places in the CSSOM where we're doing weird array-like things, and if so can we swap them all at the same time?<br>
&lt;fantasai> TabAtkins: I believe that's it for CSSOM, have a pending edit for TypedOM<br>
&lt;fantasai> ... which currently uses a better version of fake arrays<br>
&lt;fantasai> ... but I think in CSSOM CSSRuleList is the only actual list we have<br>
&lt;fantasai> ... everything else is individual rules<br>
&lt;fantasai> plinss: Would be good to do a quick pass over everything else, do them all<br>
&lt;fantasai> TabAtkins: been looking over OM, and everything seems to use CSSRuleList, and Declaration doesn't expose anything like that<br>
&lt;fantasai> ... theoretically we could also make CSSStyleDeclaration an ObservableArray, since it has indexed getting/setting<br>
&lt;fantasai> ... happy to look into it<br>
&lt;fantasai> plinss: or making it something maplike or whatever, but in any case modernize anything that should be modernize it<br>
&lt;fantasai> TabAtkins: should raise as a separate issue<br>
&lt;fremy> I believe CSSStyleDeclaration should not be made an ObservableArray<br>
&lt;fantasai> ... only other one that fits in this area, I think<br>
&lt;astearns> ack matthieudubet<br>
&lt;fremy> Otherwise, there can be conflicts between CSS property names and Array methods<br>
&lt;fantasai> matthieudubet: CSSGroupingRule and now CSSStyleRule are really similar implementation-wise<br>
&lt;fantasai> ... insertRule/deleteRule are exactly the same<br>
&lt;fantasai> ... should we expose those as (??)<br>
&lt;fantasai> ... or share code only in the implementation<br>
&lt;fantasai> TabAtkins: those all have .cssRules, and then they have legacy insertRule/deleteRule<br>
&lt;fantasai> ... if we wanted we could pull those two methods out into a mixin, but that wouldn't be a behavior change<br>
&lt;fantasai> ... just better organized specification<br>
&lt;emeyer> fantasai: I was following up on emilio’s concern that we define stuff that doesn’t do anything.<br>
&lt;fantasai> s/stuff/methods/<br>
&lt;fantasai> TabAtkins: just don't call them<br>
&lt;fantasai> TabAtkins: having something be a real array is valuable, and having it behave like an array but not have all the methods is hard and unnatural in JS<br>
&lt;fantasai> astearns: Proposed resolution is redefine CSSRuleList as ObservableArray, with all of the readonly bits defined<br>
&lt;fantasai> ... particularly carefully since this is the first time we're defining such a readonly ObservableArray<br>
&lt;fantasai> RESOLVED: Redefine CSSRuleList as ObservableArray<br>
&lt;fantasai> astearns: and also follow-up issue about CSSStyleDeclaration?<br>
&lt;fantasai> ACTION: TabAtkins to file issue about CSSStyleDeclaration's array upgrade<br>
</details>


-- 
GitHub Notification of comment by css-meeting-bot
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/8350#issuecomment-1497776457 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Wednesday, 5 April 2023 16:22:01 UTC