Weak event listener

Jason Orendorff jason.orendorff at gmail.com
Tue Mar 26 12:25:25 PDT 2013


On Mon, Mar 25, 2013 at 9:29 PM, Erik Arvidsson
<erik.arvidsson at gmail.com> wrote:
> WeakMap would not work in this specific case since a WeakMap cannot be
> iteratered.

What would work here is determinism:
    https://gist.github.com/jorendorff/5245857
For this, a deterministic API is just as easy to use, easier to
implement, and easier to reason about.

The main justification I’ve heard for WeakRef is that sometimes it’s
hard to unhook observers at the point where you find you don't want
them anymore. That’s plausible. I'd really appreciate some better
examples of how this comes up and (especially) how WeakRef helps in
practice. The References section of the strawman is just a collection
of links to reactive libraries like Tangle[1], without elaboration.
But if Tangle actually used weak observer semantics, even the most
basic Tangle use cases would break! [2]

I don't mean to pick on WeakRef. Across the board, I would love to see
better motivating use cases for all proposals: less contrived, and
actually illustrating the benefit of the proposal. I don’t think it’s
too much to ask.

The modules proposal has suddenly gone from one of the worst-motivated
proposals in ES6 to perhaps the best, with scads of excellent use
cases. More of that, please!

-j

[1]http://worrydream.com/Tangle/

[2]http://worrydream.com/Tangle/Examples/CookieExample.js
Note that after the observer is hooked up, it immediately becomes
unreachable (except via Tangle itself) as soon as that function
returns.


More information about the es-discuss mailing list