-
Notifications
You must be signed in to change notification settings - Fork 56
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
ObservableArray, and its use by adoptedStyleSheets #693
Comments
Thanks @mfreed7 for filing this! I re-read whatwg/webidl#796 (ah, 2019, what an innocent time) and found that while the "Background" section holds up great, the "Solutions" section doesn't capture some of how our thinking evolved. So to provide some additional color there:
I'll also point out that the example in https://webidl.spec.whatwg.org/#example-af5d265e is pretty explainer-ish and might be a helpful read. |
Discussed during our F2F. Apologies this took so long. This looks great! One request here would be to consider exposing this to web developers as well (make it a constructable object, instead of a trait) - and possibly bring it to TC39. WDYT? |
Thanks!
@domenic WDYT? |
I've been in favor of giving developers a nice way to create observable arrays since the beginning; see some of the discussion in whatwg/webidl#796. The latest shape (after the course corrections mentioned in #693 (comment)) makes this a bit trickier. Part of the reason the current solution is so good is precisely because it is "just a (proxy for an) So this means the creation of these things would need to look a bit different, perhaps The other hard part of exposing this functionality to developers is that we'd then need to come up with a nice-to-use API that is good for all time, instead of just creating something that works for spec developers and can be tweaked any time. The spec-author facing hooks are:
but I'd be hesitant to say these are the best possible API, or can be expressed nicely in JS (as opposed to in spec language). As a simple example, in spec land we're representing an assignment, e.g. So overall I think it would be a significant project to make these developer-creatable, which would benefit from research, maybe some cowpath-paving libraries, and so on. Probably the first step, before investing too much, is to find out if there's demand for this sort of thing. |
Braw mornin' TAG!
I'm requesting a TAG review of
ObservableArray
, and its use byadoptedStyleSheets
.This is essentially one new idea, the
ObservableArray
IDL type, plus one use of that new type, for theadoptedStyleSheets
API. While it would seem that these might constitute two separate TAG reviews, I think it makes sense to review them together, since one proves the use case for the other. Also,adoptedStyleSheets
by itself is already a specified, shipped API, and we're just talking about converting it fromFrozenArray
toObservableArray
. LMK if you disagree.Motivation/Summary
Various Web APIs require an array-ish class to represent a list of things. However, for various reasons (enumerated on the issue), fake arrays have always been used in these cases. Examples include
NodeList
andHTMLOptionsCollection
. These are similar to arrays, but they cannot be used in the same ways that standard Javascript arrays are used, e.g. through.map()
,.filter()
,.concat()
, and.push()
. TheFrozenArray
type is used in some places, but it also has downsides, such as being immutable.The
ObservableArray
WebIDL type is designed to solve the above problems. It provides a mutable array with spec hooks into the set and remove behaviors, so that mutations can be properly tracked or blocked.The
adoptedStyleSheets
API previously used theFrozenArray
type to represent the list ofCSSStyleSheets
. The spec was recently changed to represent it as an assignableObservableArray
, which should be backwards-compatible, but also expand the usability by allowing array mutations in place.Links
ObservableArray
explainer is provided by the introductory comment on this issue: A new approach to array-ish classes whatwg/webidl#796adoptedStyleSheets
and constructable stylesheets APIs. New tests of the use ofObservableArray
will be added once this PR lands.ObservableArray
PR and the issue discussing using it foradoptedStyleSheets
.Further details:
adoptedStyleSheets
assignable. WebKit feels that an assignable attribute is a vector for race conditions. Most/all other participants, including other implementers and many large developers agree that race conditions can happen whenever/howeverawait
is used, and the proposed API is the least risky. This has been extensively discussed.We'd prefer the TAG provide feedback as (please delete all but the desired option):
💬 leave review feedback as a comment in this issue and @-notify @mfreed7 @domenic
The text was updated successfully, but these errors were encountered: