Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you remove a dojo connected event if you do not have the "handle" that was returned during the dojo.connect?

How do you remove a dojo connected event if you do not have the "handle" that was returned during the dojo.connect?

My example involves dynamically assigning a set of events to a set of objects. (for simplicity, the events are onclick and ondblclick, and the objects are rows within a table)

So, during page setup events are connected to each row (onclick, ondblclick). Now, depending on user desires/actions, a need for removal of one event from one row is required. But the original handle is no longer available. Because of this the following will not work: dojo.disconnect(row, "onclick", ??*). How do I get around this without hacking the original row structure?

Any help is of course greatly appreciated.

like image 454
Bear Avatar asked Jul 31 '09 20:07

Bear


2 Answers

The answer to your question is that is it impossible to disconnect event if you have lost the "handle" that was returned during the dojo.connect operation. Except if you are ready to do heavy hacking of dojo code itself.

You must store these somewhere if you wish to disconnect them later on.

like image 138
xApple Avatar answered Sep 20 '22 08:09

xApple


Like Seth I have my patterns for removing events — I collect handles in arrays (pseudo-code):

var handles = [
  dojo.connect(...),
  dojo.connect(...),
  dojo.connect(...)
];

If I connect dynamically I just collect them:

var handles = [];
...
handles.push(dojo.connect(...));
...
handles.push(dojo.connect(...));

If I connect several events in a regular manner I can use dojo.map():

var handles = dojo.map(["click", "ondblclick"], function(evt){
  return dojo.connect(node, evt, ...);
});

The neat part is that later I can disconnect them all with a handy one-liner:

dojo.forEach(handles, dojo.disconnect);

In your case you can use a dictionary like shown by Seth to accomplish the same:

var handles = {};
...
handles[node.id] = dojo.map(["click", "ondblclick"], function(evt){
  return dojo.connect(node, evt, ...);
});

So later one you can disconnect handlers like this:

dojo.forEach(handles[node.id], dojo.disconnect);

See if Seth' and my sketches help in your case. If not, give us more details.

like image 44
Eugene Lazutkin Avatar answered Sep 21 '22 08:09

Eugene Lazutkin