Re: [cssom] Constructable Stylesheets

On Wed, Apr 8, 2015 at 2:48 AM, François REMY
<francois.remy.dev@outlook.com> wrote:
> My point is that we don't want to force people to poll these collections every now and then to find out if/when something is added/removed. To sum up, my current opinion is that your proposal is adding complexity to the platform without giving developers the necessary tools to deal with it.
>
> If we dissociate my "it seems like I liked the fact stylesheets are all defined in the DOM after all" opinion from the rest of my arguments, it still remains that when a stylesheet is added to a document, I can currently know about it using MutationEvents. As a consequence, I would friendly "oppose" Constructable StyleSheets if we don't get at the same time at least some reflection events like "stylesheet added, stylesheet removed, stylesheet updated" and (optionally), for individual stylesheets "rule added, rule removed, rule updated" (something we can't have at this point).
>
> That would make it possible to reach parity with what we can currently achieve, and in a way that's arguably better than what we have now. I would also like stylesheet.parentCollection to return document.moreStylesheets so that I can know where the stylesheet is defined.

Ah, okay.  I'm not opposed to such a set of events or whatnot.
Ideally it should be doable by having document.styleSheets and
document.moreStyleSheets emit mutation records, so you could just use
a MutationObserver directly on it (rather than having to watch the
entire document for <link>/<style> changes).

> And if, in addition, we get Meta APIs like "remove()" which would DoTheRightThing™ (remove the parentNode if any, remove the @import rule if any, remove from the moreStylesheet collection if any, etc...) then I would even approve the API.

Interesting!  Given that there are three completely different ways to
remove a stylesheet (remove the element from the document, remove the
manually-constructed stylesheet from the moreStyleSheets array, remove
the @import rule from the containing stylesheet's OM), such a
convenience API seems to make a lot of sense, if we expect stylesheets
to be manipulated more often.

~TJ

Received on Wednesday, 8 April 2015 23:47:05 UTC