Adopt EventEmitter class instead of injecting Signal methods

Introduce a new class, EventEmitter, which implements signal
handling for pure JavaScript classes. EventEmitter still
utilizes GJS' addSignalMethods internally.

EventEmitter allows static typechecking to understand the
structure of event-emitting JS classes and makes creating
child classes simpler.

The name 'EventEmitter' mirrors a common name for this pattern
in Node and in JS libraries.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2043>
This commit is contained in:
Evan Welsh
2022-07-04 18:30:44 -04:00
parent 9e30afe678
commit a88e59c1a8
39 changed files with 204 additions and 169 deletions

View File

@ -1,7 +1,7 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
/* exported NMApplet */
const { Clutter, Gio, GLib, GObject, Meta, NM, Polkit, St } = imports.gi;
const Signals = imports.signals;
const Signals = imports.misc.signals;
const Animation = imports.ui.animation;
const Main = imports.ui.main;
@ -107,8 +107,10 @@ function launchSettingsPanel(panel, ...args) {
}
}
var NMConnectionItem = class {
var NMConnectionItem = class extends Signals.EventEmitter {
constructor(section, connection) {
super();
this._section = section;
this._connection = connection;
this._activeConnection = null;
@ -193,10 +195,11 @@ var NMConnectionItem = class {
this._sync();
}
};
Signals.addSignalMethods(NMConnectionItem.prototype);
var NMConnectionSection = class NMConnectionSection {
var NMConnectionSection = class NMConnectionSection extends Signals.EventEmitter {
constructor(client) {
super();
if (this.constructor === NMConnectionSection)
throw new TypeError(`Cannot instantiate abstract type ${this.constructor.name}`);
@ -320,7 +323,6 @@ var NMConnectionSection = class NMConnectionSection {
this._sync();
}
};
Signals.addSignalMethods(NMConnectionSection.prototype);
var NMConnectionDevice = class NMConnectionDevice extends NMConnectionSection {
constructor(client, device) {
@ -1242,8 +1244,10 @@ class NMWirelessDialog extends ModalDialog.ModalDialog {
}
});
var NMDeviceWireless = class {
var NMDeviceWireless = class extends Signals.EventEmitter {
constructor(client, device) {
super();
this._client = client;
this._device = device;
@ -1433,7 +1437,6 @@ var NMDeviceWireless = class {
return 'network-wireless-no-route-symbolic';
}
};
Signals.addSignalMethods(NMDeviceWireless.prototype);
var NMWireguardItem = class extends NMConnectionItem {
_buildUI() {
@ -1657,7 +1660,6 @@ var NMVpnSection = class extends NMConnectionSection {
return '';
}
};
Signals.addSignalMethods(NMVpnSection.prototype);
var DeviceCategory = class extends PopupMenu.PopupMenuSection {
constructor(category) {