Node.setUserData/Node.getUserData #47

Open
Benvie opened this Issue May 3, 2012 · 3 comments

Projects

None yet

2 participants

@Benvie
Benvie commented May 3, 2012

https://developer.mozilla.org/En/DOM/Node.setUserData

These are useful apis that obsolete expandos and jQueries hideous method that also doesn't allow proper garbage collection of the JS objects when they're object graph is isolated to DOM nodes aside from the cache that keeps them alive. It's available in Firefox but apparently nowhere else I'vee been able to find and I'm not sure why.

I've done a couple test implementations of it. One relies on WeakMaps to supply the storage, another uses addEventListener and a custom event to create a storage that is only referenced by the DOM node it lives inside as part of being a registered event listener.

The WeakMap one is here: https://github.com/Benvie/svgstuff/blob/master/lib/user-data.js
The event based one isn't complete, but the core principle is demonstrated here: https://gist.github.com/2586308

@Raynos
Owner
Raynos commented May 3, 2012

The remainder of interfaces and interface members listed in this section were removed to simplify the DOM platform. Implementations conforming to this specification will not support them.

...

getUserData
setUserData

As nice as those methods are they are deprecated in DOM4.

Why can't you use .dataset instead?

@Benvie
Benvie commented May 3, 2012

wtf how did I miss that. Also dataset just stores strings. There's not other way provided by the DOM to specifically associate JS objects with a DOM element such that when the DOM element dies so does the data. Oh well, these shims will work for the time being.

@Raynos
Owner
Raynos commented May 3, 2012

We should raise this issue with the DOM. Make a thread on the mailing list.

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