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

DOMStringMap has no mechanism to add/remove/change values #127

Open
parlough opened this issue Dec 20, 2023 · 4 comments
Open

DOMStringMap has no mechanism to add/remove/change values #127

parlough opened this issue Dec 20, 2023 · 4 comments

Comments

@parlough
Copy link
Member

DOMStringMap, primarily returned by HTMLElement#dataset does not provide any mechanism to set or access its values.

Would be nice if it implemented something like Map<String, String> if that was possible :)

@kevmoo
Copy link
Member

kevmoo commented Dec 20, 2023

I've ran into this, too! CC @srujzs

@srujzs
Copy link
Contributor

srujzs commented Dec 21, 2023

I'm surprised we don't emit some properties already:

https://github.com/w3c/webref/blob/8d7678e1740d00c3b79ebf70013d0448b23e3c8b/ed/idl/html.idl#L161

It might be due to us not handling getter and setter? Maybe we should emit them using [] and []=. https://webidl.spec.whatwg.org/#idl-special-operations

That being said, I don't think we can feasibly implement Map (or any Dart collections type), but hopefully the indexing operations are enough!

@adrianlmm
Copy link

This one is a show stopper for me, I can't start the migration from 'dart:html' to 'web' until it gets fixed.

@srujzs
Copy link
Contributor

srujzs commented Feb 27, 2024

Can you describe a bit more on what's affecting your migration? If it's the above indexing operators, you can define your own external extension members on any interop type if they're not available: https://dart.dev/interop/js-interop/usage#extension-members-on-interop-types e.g.

import 'dart:js_interop';
import 'dart:js_interop_unsafe';

extension on DOMStringMap {
  external String operator [](String name);
  external void operator []=(String name, String value);
  void delete(String name) => this.delete(name.toJS);
}

Matching the definition here: https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes:domstringmap-3.

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

No branches or pull requests

4 participants