Skip to content

Conversation

@Raynos
Copy link
Collaborator

@Raynos Raynos commented Mar 24, 2014

This increments data-set to version 3.0.0

Previously this would fail h("foo", { 'data-foo': { 'some': 'object' } }) because the native browser dataset would serialize non string values to strings.

data-set v3.0 fixes this and you can correctly store objects on an element and later retrieve them using the 'data-set' module.

This is a back compat breaking change as people can no longer access their 'data-*' keys in .dataset compliant browsers using elem.dataset.foo they have to use DataSet(elem).foo

Recommend major version bump if accept.

@Raynos
Copy link
Collaborator Author

Raynos commented Mar 24, 2014

As an added bonus, I just create 3.0.0 which reduced the size from 10kb to 3kb :)

@Raynos
Copy link
Collaborator Author

Raynos commented Mar 24, 2014

Since html-element does not use data-set for reading 'data-*' attributes this breaks serializing of 'data-*' attributes.

Either the data-set module needs fixing or html-document can use data-set for reading data.

@dominictarr
Copy link
Collaborator

what changed in dataset? does it store objects as JSON now or something like that?
how would they get the data out if they didn't use your module? show me the code.

@Raynos
Copy link
Collaborator Author

Raynos commented Mar 25, 2014

@dominictarr so data-set always weakly attached data on the dom element if native elem.dataset was not supported.

This means currently in IE<11 to access data you put in hyperscript elements you would have to use DataSet(elem).key

Now due to elem.dataset converting values into strings, I've removed the native usage and always use the weak attaching of data approach.

Which means to read data-* properties out of dom elements you would have to do:

var h = require('hyperscript')
var DataSet = require('data-set')
var assert = require('assert')

var elem = h('div', {
  'data-foo': { bar: 'baz' }
});
var ds = DataSet(elem)
assert.deepEqual(ds.foo, { bar: 'baz' })

Previously if you accessed elem.dataset.foo or elem.getAttribute('data-foo') your code would have failed in IE<11. i.e. not accessing 'data-' attributes through the data-set module is a leaky cross browser abstraction.

@Raynos
Copy link
Collaborator Author

Raynos commented Mar 25, 2014

A valid alternative to this PR is to completely remove the dependency on data-set and do elem.setAttribute(key, value).

@dominictarr
Copy link
Collaborator

oh... so are you saying that although data-set started as a polyfill for data- attributes, you have removed that completely and now it's not using that at all?

@Raynos
Copy link
Collaborator Author

Raynos commented Mar 25, 2014

@dominictarr it started off as a polyfill for data- attributes that was

function DataSet(elem) {
  return elem.dataset ? dataset : polyfill(elem)
}

Now it's

function DataSet(elem) {
  return polyfill(elem)
}

The polyfill always weakly attached the dataset to the element.

The important back compat breaking change is ( npm-dom/data-set@3f0ec1a )

@dominictarr
Copy link
Collaborator

right - so it's not a polyfil anymore! it's just a weakmap! but it looks like it's it's a polyfil.
I think this would be quite surprising to users of this module.
This is a module for generating html, so sticking to the standards makes sense, and strapping on new features (like weakmaps) doesn't.

Is there another way you can use weakmaps like you are without me merging this?

@Raynos
Copy link
Collaborator Author

Raynos commented Mar 25, 2014

@dominictarr thinking about it more I think I should close this and you should remove data-set completely and call elem.setAttribute('data-foo', value).

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

Successfully merging this pull request may close these issues.

2 participants