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:
@ -4,7 +4,7 @@
|
||||
// the following is a modified version of bolt/contrib/js/client.js
|
||||
|
||||
const { Gio, GLib, GObject, Polkit, Shell } = imports.gi;
|
||||
const Signals = imports.signals;
|
||||
const Signals = imports.misc.signals;
|
||||
|
||||
const Main = imports.ui.main;
|
||||
const MessageTray = imports.ui.messageTray;
|
||||
@ -49,8 +49,10 @@ const BOLT_DBUS_CLIENT_IFACE = 'org.freedesktop.bolt1.Manager';
|
||||
const BOLT_DBUS_NAME = 'org.freedesktop.bolt';
|
||||
const BOLT_DBUS_PATH = '/org/freedesktop/bolt';
|
||||
|
||||
var Client = class {
|
||||
var Client = class extends Signals.EventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this._proxy = null;
|
||||
this.probing = false;
|
||||
this._getProxy();
|
||||
@ -127,11 +129,12 @@ var Client = class {
|
||||
return this._proxy.AuthMode;
|
||||
}
|
||||
};
|
||||
Signals.addSignalMethods(Client.prototype);
|
||||
|
||||
/* helper class to automatically authorize new devices */
|
||||
var AuthRobot = class {
|
||||
var AuthRobot = class extends Signals.EventEmitter {
|
||||
constructor(client) {
|
||||
super();
|
||||
|
||||
this._client = client;
|
||||
|
||||
this._devicesToEnroll = [];
|
||||
@ -217,7 +220,6 @@ var AuthRobot = class {
|
||||
return GLib.SOURCE_REMOVE;
|
||||
}
|
||||
};
|
||||
Signals.addSignalMethods(AuthRobot.prototype);
|
||||
|
||||
/* eof client.js */
|
||||
|
||||
|
Reference in New Issue
Block a user