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,10 +1,11 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
/* exported ScreenShield */
const {
AccountsService, Clutter, Gio,
GLib, Graphene, Meta, Shell, St,
} = imports.gi;
const Signals = imports.signals;
const Signals = imports.misc.signals;
const GnomeSession = imports.misc.gnomeSession;
const OVirt = imports.gdm.oVirt;
@ -44,8 +45,10 @@ var CURTAIN_SLIDE_TIME = 300;
* This will ensure that the screen blanks at the right time when it fades out.
* https://bugzilla.gnome.org/show_bug.cgi?id=668703 explains the dependency.
*/
var ScreenShield = class {
var ScreenShield = class extends Signals.EventEmitter {
constructor() {
super();
this.actor = Main.layoutManager.screenShieldGroup;
this._lockScreenState = MessageTray.State.HIDDEN;
@ -676,4 +679,3 @@ var ScreenShield = class {
});
}
};
Signals.addSignalMethods(ScreenShield.prototype);