linuxmint/Cinnamon — pull request #1780 by Lusito (2013-03-10 11:13:52+00:00)
Title: [WIP] Easier connection management

@autarkper recently closed #1737, which added connector.js, a concept to ease the connection management.

I had a similar idea for a while now, especially for applets, since currently most don't even bother to disconnect from their signals.
So, my approach has 3 different ways you can choose to use:

- Connector.createConnection(object, 'signal', callback, ....);
- You can essentially replace any object.connect('signal', callback, ...) with this one.
- Returns a new Connection object, which has methods disconnect, forget and getTarget
- This can be used if you only have a single connection to manage.
- let connector = new Connector.Connector();
- This is a connection manager which keeps a list of connections and supplies these methods:
- createConnection(..): same parameters as the manual function above
- Also returns the connection object, so you can choose to forget or disconnect a single connection separate from all others.
- The connection will be stored internally
- destroyConnections()
- Calls disconnect on all connections and then clears the connections array.
- setMaster(master, signal)
- If a master is set, the manager will watch that object for the specified destruction signal.
- When master emits signal, destroyConnections() will be called as well as setMaster(null)
- Any previously set master object will be disconnected from.
- Connector.addConnectorMethods(MyClass.prototype);
- This adds createConnection, destroyConnections and setConnectionMaster to the class prototype.
- This uses a Connector instance internally, so you don't have to create a connector manually and can skip the connector variable.