Raynos / DOM-shim

Shims out the entire DOM4 API
http://raynos.github.com/DOM-shim/test/test.html
155 stars 15 forks source link

Node.setUserData/Node.getUserData #47

Open ghost opened 12 years ago

ghost commented 12 years ago

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 commented 12 years ago

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 commented 12 years ago

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 commented 12 years ago

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