Skip to content
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

Dictionary mixins #195

Open
annevk opened this issue Oct 21, 2016 · 9 comments
Open

Dictionary mixins #195

annevk opened this issue Oct 21, 2016 · 9 comments

Comments

@annevk
Copy link
Member

annevk commented Oct 21, 2016

ExtendableMessageEvent defined at https://w3c.github.io/ServiceWorker/#extendablemessage-event-section and MessageEvent defined at https://html.spec.whatwg.org/multipage/comms.html#messageevent are extremely similar.

To duplicate less and consolidate fixes in a single place it would be better if they used a shared mixin. However, that would not work for initializing them as the dictionaries would still need to have the duplication.

Thus, the need is born for dictionary mixins.

Background: w3c/ServiceWorker#989.

@bzbarsky
Copy link
Collaborator

This specific case can't be handled with dictionary inheritance?

The general case of multiple specs all wanting to add stuff to multiple dictionaries can't be handled that way, of course, but the specific cases of "multiple specs wanting to add stuff to a single dictionary" case is handled by partial dictionary and afaict "multiple specs wanting to share a single dictionary definition but extend it" is handled by dictionary inheritance. Unlike interface inheritance, dictionary inheritance has very little in the way of observable properties (nothing apart from [[Get]] ordering), so should be quite usable as a specification device as needed here.

We can probably do full-on dictionary mixins, but I'd like to see a better justification for the resulting complexity, both in terms of spec and in terms of implementations.

@annevk
Copy link
Member Author

annevk commented Oct 21, 2016

The problem with inheritance is that we have Event (EventInit dict) > MessageEvent (MessageEventInit dict) and on the other side we have Event (EventInit dict) > ExtendableEvent (ExtendableEventInit dict) > ExtendableMessageEvent (ExtendableMessageEventInit dict).

I don't really see how to make that work. (If inheritance worked for dictionaries here it would also work for the interface side of things, no?)

@bzbarsky
Copy link
Collaborator

Oh, I see. I hadn't realized that the ExtendableEventInit thing was in there too.

Then yeah, doing this does require mixins. :(

@palemieux
Copy link

@tobie Any follow-up on the plan to add dictionary mixins (#363 (comment))? This would help document only once properties used in multiple dictionary types.

@tobie
Copy link
Collaborator

tobie commented Nov 2, 2018

None at present, unfortunately.

@palemieux
Copy link

@tobie Ok. In the meantime, any recommendation for specifying complex dictionary structures intended to be passed to Web APIs?

@dcrousso
Copy link

Is there still any interest in adding this? I have a possible use for it in WebKit.

In my opinion, allowing dictionary mixin (and partial dictionary mixin) seems like a natural way to compose objects, especially since there is no class/prototype that's created/exposed for a dictionary to the page. dictionary is really just a bag of key->value, so where each of those key->value comes from (whether that be via direct inheritance or some includes) isn't really that important.

@bathos
Copy link
Contributor

bathos commented Mar 30, 2021

@dcrousso the property [[Get]] order, as bzbarsky mentioned, does expose the inheritance chain to ES code. Within a single "tier", keys are sorted lexically, but the access order is one-tier-at-a-time. If they were always sorted across the chain, the exposure would go away, but that likely isn't web compatible (and might lead to problems for implementers).

One ordering solution for mixins would be to handle them like partials: "these keys belong to the includes-target, so they get sorted lexically among the others". I'm pretty sure that would keep the access order well-defined without borking anything that already exists?

@annevk
Copy link
Member Author

annevk commented Apr 12, 2021

For dictionaries in particular I think we should keep lexicographical ordering. If we have dictionary mixins, that would be across all of the members. I agree that's not possible for interfaces/classes. There per-thing is probably the best we can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants