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

Node.setUserData/Node.getUserData #47

Open
ghost opened this issue May 3, 2012 · 3 comments
Open

Node.setUserData/Node.getUserData #47

ghost opened this issue May 3, 2012 · 3 comments

Comments

@ghost
Copy link

ghost 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
Copy link
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?

@ghost
Copy link
Author

ghost 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
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant