Page 1 of 2

Disconnect class ?

Posted: 17 August 2015, 14:39
by Coin-coin le Canapin
Hi.
I need to use connectClass on some elements in a given function and disconnect them later inside another function. Is it possible ?

Re: Disconnect class ?

Posted: 17 August 2015, 16:02
by Quinarbre
Hi,

Simple yet brutal solution (be sure to use this.connect instead of dojo.connect) :

Code: Select all

this.disconnectAll();
If you need something more subtle, you'll need to store the handlers for each connected object, so you'll have to replace

Code: Select all

dojo.connectClass( 'class', ... )
with

Code: Select all

dojo.query( '.class').forEach( ... )
and store the handlers there.

Re: Disconnect class ?

Posted: 17 August 2015, 18:24
by Coin-coin le Canapin
Thank you.
I'll try both. :)

What's the right way to store the handlers in order to make them available from other functions ? Should I store them in this.handlers for example ?

Re: Disconnect class ?

Posted: 17 August 2015, 21:07
by apollo1001
This post fixed all my issues on the topic - happy reading:
http://forum.boardgamearena.com/viewtop ... 917#p10917

Re: Disconnect class ?

Posted: 17 August 2015, 21:22
by Rudolf
dojo.addclass(zeclasse)
dojo.query(zeclasse).connect(....)




dojo.query(zeclasse).disconnect
dojo.removeclasse(zeclasse)


;)

Re: Disconnect class ?

Posted: 17 August 2015, 21:45
by Coin-coin le Canapin
apollo1001 wrote:This post fixed all my issues on the topic - happy reading:
http://forum.boardgamearena.com/viewtop ... 917#p10917
Yeah I looked at the function code this afternoon and I saw that all the handlers were stored into this.connections :)
I'm writing a function that will disconnect only handlers of a given class instead of disconnecting ALL the handlers.

Rudolf : dojo.query(".class").disconnect actually works ? Would be the simplest way to achieve what I want.
I also tought that we couldn't use .connect on a class and that's why BGA admin added the connectClass functions on the framework.

Re: Disconnect class ?

Posted: 18 August 2015, 01:08
by pikiou
I don't think Rudolf's solution works: you dojo.disconnect a handler, not an element.

You can use dojo.query('.myClass').connect(....) but it will return a list of elements, not the list of handlers you'd have needed for dojo.disconnect

I think what you're looking for is this:

Code: Select all

disconnectClass: function(className, optionalEvent) {
   dojo.forEach(this.connections, function(connection) {
      if (dojo.hasClass(connection.element, className) && (!optionalEvent || connection.event == optionalEvent)) {
         dojo.disconnect(connection.handle);
      }
   });
},
(I didn't test it...)

Re: Disconnect class ?

Posted: 18 August 2015, 09:52
by Rudolf
Ok... I does remember I've tried that a few years ago (and maybe unsucceed) ... sorry if it's wrong. WIth last game, I used an array of connections ... lack of memory... i'm getting old :)

Re: Disconnect class ?

Posted: 18 August 2015, 10:01
by Rudolf
with a query (and storage in node, I suppose it's a good way to manage this, then when node is destroyed, connection is destroyed,...):
(storage direct in node)
node.connexions = [];
node.connexions.push(dojo.connect(node, ...));

then disconnect all:
dojo.query("*").forEach(function(node) {if (typeof node.connexions!="undefined") dojo.forEach(node.connexions, "dojo.disconnect(item)"); });

Re: Disconnect class ?

Posted: 18 August 2015, 10:29
by Rudolf
I've found the post when the pb was discussed:
http://forum.boardgamearena.com/viewtop ... =12&t=3045