W3C home > Mailing lists > Public > www-dom@w3.org > July to September 2000

event registration another way

From: John Ky <hand@syd.speednet.com.au>
Date: Wed, 27 Sep 2000 01:03:17 +1000
Message-ID: <007b01c027ca$edd6faa0$d000a8c0@NEWHOGGY>
To: <www-dom@w3.org>
    If multiple identical EventListeners are registered
    on the same EventTarget with the same parameters
    the duplicate instances are discarded. They do not
    cause the EventListener to be called twice and since
    they are discarded they do not need to be removed
    with the removeEventListener method. 

I assume the above "multiple identical EventListeners"
refers to object identity.

If I had it my way, I'd rather that removeEventListener
method had to be called as many times as addEventListener
but still insist that the event listener be called only once.

For instance:

Function 1 adds an event listener to an event listener
because it wants to check something when the specified
event has occured.

Function 2 does the same.

If both functions add use a "different"* event listener.
Two event listeners will be called.  This may be what
is wanted.

Suppose it is not - maybe for consistency or
performance reasons.  Should both functions
register the same event listener?  

That won't always work:

Function 1 {
    add event listener
    other code a
    Function 2
    other code b
    remove event Listener

Function 2 {
    add eventlistener
    other code c
    remove event listener

Calling Function 1 would leave "other code b" unchecked
even if that was the intent.  (ie. the event handler doing
checks is no longer registered as it was unregistered by

This means code which adds and removes an event 
listener can't be ignorant of code elsewhere which
adds and removes the same event listener.  That's a
blow to manageability where being able to be safely
ignorant is bliss.

It would be desireable (I think) if it were possible to
code according to local rather global assumptions.

Think of COM's AddRef and Release as an
example. As long as you handle reference counting
for a COM object properly in local code that's all
that matters.

That's the way event registration ought to be -
if not universally then perhaps by allowing users
of the DOM API to adjust the behaviour to this
if it suits them.



* different meaning different object identity but the
same handler code
Received on Tuesday, 26 September 2000 10:04:15 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:07 UTC