Remove All events except a specific set of event

68 views
Skip to first unread message

Markus

unread,
May 15, 2012, 10:29:04 AM5/15/12
to closure-lib...@googlegroups.com
Hello everyone,
this is my problem.
I've differents modules.
Each module manages a set of events.
The wrapper class loads these modules.
The wrapper loads dinamically a module and removes it from the dom,
and i want give it the ability to remove also the events associated with the module.
There a way to say closure :
goog.events.removeAll();

but except "x event"??

Thx

Andre Tannus

unread,
May 15, 2012, 7:27:03 PM5/15/12
to closure-lib...@googlegroups.com

What I do is keep track of the events I set so that I can remove them when I want to.
When you add an event with goog.events.listen(...) it returns a unique Key, which you can pass into goog.events.unlistenByKey().

Andre

--
A ciência consiste em perturbar um sistema e analisar sua reação. Eu, sou uma perturbação.

André Tannús | Ideas at Epungo
ata...@epungo.com.br | +55 11 8053-7636 | +55 11 2389-4360 

"Somewhere, something incredible is waiting to be known."
Carl Sagan

Rhys Brett-Bowen

unread,
May 15, 2012, 8:55:19 PM5/15/12
to Closure Library Discuss
goog.ui.component has getHandler() which you can use instead of
goog.events (this.getHandler().listen(....)) and when it's disposed
those events will be removed.

looking in to good.ui.component there is this line:

= new goog.events.EventHandler(this)

so you could setup a new EventHandler for each module.

module1.handler = new goog.events.EventHandler(module1);
module1.listen.....

then use removeAll on it later

Markus

unread,
May 17, 2012, 3:49:01 AM5/17/12
to closure-lib...@googlegroups.com
Thanks.
I use already a similar tecnique inside a class that wrap a specific events,
but I load the modules that are not components.
In that case i must call a method at a time for "unlisten" in each class.
So,  i thought to built a method that in one point remove all events except a specific set of keys..

Markus

unread,
May 18, 2012, 6:26:58 AM5/18/12
to closure-lib...@googlegroups.com
I tryed to replicate the code inside goog.events.removeAll()
but the id of listener, i don't know why, changes during computation..
Any suggestion? 

Reply all
Reply to author
Forward
0 new messages