Disconnect class ?

Game development with Board Game Arena Studio
User avatar
Coin-coin le Canapin
Posts: 163
Joined: 31 January 2013, 19:00

Disconnect class ?

Post 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 ?
User avatar
Quinarbre
Posts: 140
Joined: 15 December 2013, 23:26

Re: Disconnect class ?

Post 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.
User avatar
Coin-coin le Canapin
Posts: 163
Joined: 31 January 2013, 19:00

Re: Disconnect class ?

Post 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 ?
User avatar
apollo1001
Posts: 191
Joined: 21 July 2015, 10:41

Re: Disconnect class ?

Post by apollo1001 »

This post fixed all my issues on the topic - happy reading:
http://forum.boardgamearena.com/viewtop ... 917#p10917
User avatar
Rudolf
Posts: 566
Joined: 24 December 2011, 23:04

Re: Disconnect class ?

Post by Rudolf »

dojo.addclass(zeclasse)
dojo.query(zeclasse).connect(....)




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


;)
User avatar
Coin-coin le Canapin
Posts: 163
Joined: 31 January 2013, 19:00

Re: Disconnect class ?

Post 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.
User avatar
pikiou
Posts: 389
Joined: 03 October 2011, 05:36

Re: Disconnect class ?

Post 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...)
User avatar
Rudolf
Posts: 566
Joined: 24 December 2011, 23:04

Re: Disconnect class ?

Post 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 :)
Last edited by Rudolf on 18 August 2015, 10:06, edited 1 time in total.
User avatar
Rudolf
Posts: 566
Joined: 24 December 2011, 23:04

Re: Disconnect class ?

Post 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)"); });
User avatar
Rudolf
Posts: 566
Joined: 24 December 2011, 23:04

Re: Disconnect class ?

Post by Rudolf »

I've found the post when the pb was discussed:
http://forum.boardgamearena.com/viewtop ... =12&t=3045
Post Reply

Return to “Developers”