Event Listener removal #10

Closed
davesann opened this Issue Oct 16, 2011 · 1 comment

1 participant

@davesann

I think that it is easily forgotten but good practice to remove unneeded event listeners.

Consider modification of "on" to return a list of listener ids rather than the target element.
These can be used to remove listeners with goog.events.unlistenByKey

I think that "unlistening" by function may not be possible because of the wrapper functions that you use.

as below:

(defn on [elem event func]
(let [ev-name (string/upper-case (name event))
event (aget events/EventType ev-name)
body-elem (get-body)]
(doall (map
(fn [el]
(let [parsed (->target el)]
(events/listen body-elem
event
(make-listener func parsed))))
(pclj/->coll elem)))
))

@davesann
(defn on [elem event func]
  (let [ev-name (string/upper-case (name event))
        event (aget events/EventType ev-name)
        body-elem (get-body)]
    (doall (map
             (fn [el]
               (let [parsed (->target el)]
                 (events/listen body-elem
                                event
                                (make-listener func parsed))))
             (pclj/->coll elem)))
    ))
@davesann davesann closed this Oct 16, 2011
@davesann davesann reopened this Oct 16, 2011
@davesann davesann closed this Dec 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment