Skip to content

Loading…

Implement Element.dataset #45

Open
termi opened this Issue · 5 comments

3 participants

@termi
Collaborator

I began to collect information on the possible IE8 shim.
A workaround can be found here http://eligrey.com/blog/post/html-5-dataset-support

@Raynos
Owner

The problem with dataset is this.

el.dataset.foo = "bar";
assert(el.getAttribute("data-foo") === "bar");

This basically means we need to hook getAttribute, setAttribute and hasAttribute up so that it reads from the dataset.

@termi
Collaborator

And what about for(var i in element.dataset){ } and Array.from(element.dataset)?

el.dataset.foo = "bar";

means that we need getter/setter, witch IE8 supported only for DOM Element :(

I mean we need more stronger solution.

@Raynos
Owner

You don't need getter/setters on .foo you need an ES6 proxy

In theory this should work.

  • dataset when got is pre populated with all the data- attributes
  • You can set/get on the dataset and it will store it internally somewhere.
  • Calls to getAttributes/setAttribute/attributes etc will reflect our internal dataset.
  • We may want to periodically put all the changed attributes of the internal dataset on the actual DOM node through the real APIs
@Raynos
Owner

Note things like this will never work. (not without proxies)

var e = document.createElement("div");
e.dataset.foo = "bar";
console.log(e.outerHTML);
@brettz9

Doesn't address the issues mentioned here, but I have updated the original from Eli Grey with some improvements (including some changes taking advantage of his subsequent Xccessors shim): https://gist.github.com/4093766#file_html5_dataset.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.