-
Notifications
You must be signed in to change notification settings - Fork 164
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
make hooking into maplike and setlike methods easier #824
Comments
Do we have any existing uses of such overriding? What do those look like? |
I have one where I'm trying to make a maplike when there keys used as strings are supposed to be syntactically valid css ident tokens. It looks exactly like the above, because it's @heycam who told me how to do it. (sorry, no link yet, I'm in the middle of writing the first draft of this spec, so it's not published anywhere yet). Another similar example, in a published spec, but without the IDL written yet, would be: https://drafts.csswg.org/mediaqueries-5/#script-custom-mq In either case, it would be possible to describe the effect of sticking syntactically invalid values into the map (you cannot use them from the css side, and putting it there was a waste), but it seems better to prevent them from being added to the map in the first place. |
Ah, I was about to open an issue asking for this as well (or rather, asking if spec authors really were expected to copy/paste from the ES-ese of the algos currently in WebIDL, or if we could just manipulate the "map entries" in simpler spec prose). My use-case is https://tabatkins.github.io/css-toggle/#dom, where I probably want to hook set/delete/clear to add an association between a CSSToggle and the CSSToggleMap it's in, so you can't put one object into multiple maps. |
See also #254 wherein I propose making maplike/setlike backed by Infra. (Before Infra existed, I think.) It's a bit tricky because of how MapIterator and SetIterator work but I think it's doable, with enough elbow grease. Then you could get a usage experience similar to the more-recent ObservableArray, which should hopefully be quite pleasant. |
Fixes #254. Fixes #824. This switches maplike and setlike interfaces from using a [[BackingMap]]/[[BackingSet]] ES Map/Set to use an Infra map/set instead. As explained in #254 and #824, this makes the interfaces vastly easier to work with in spec-ese (you can directly manipulate an Infra map/set, rather than having to carefully perform the ES algo dance) , and removes some undesired behavior (as currently defined, the algorithms look up and utilize the equivalent methods on Map.prototype and Set.prototype, which can be author-supplied; no implementation does this).
Currently the spec allows
clear
,delete
, andset
on a maplike interface (andadd
,clear
, anddelete
on setlike interfaces) to be overridden, so that spec authors can add validation of inserted keys and values, and to respond to changes in the contents of the backing map or set.The prose required to do this is a bit awkward. For example, to override
set
to add syntax checking for the key argument, you would need to write something like this:I think it may be better to disallow overriding these methods, but instead to have some spec hooks that are invoked from the built-in
add
,clear
,delete
, andset
functions. That way the spec author can remain in IDL value land and doesn't need to deal with invoking the built-in steps.cc @frivoal
The text was updated successfully, but these errors were encountered: