mirror of
https://github.com/edu4rdshl/gnome-shell.git
synced 2026-07-17 23:24:51 +00:00
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:
parent
9e30afe678
commit
a88e59c1a8
39 changed files with 204 additions and 169 deletions
|
|
@ -5,7 +5,7 @@
|
|||
const { GObject } = imports.gi;
|
||||
|
||||
const JsUnit = imports.jsUnit;
|
||||
const Signals = imports.signals;
|
||||
const Signals = imports.misc.signals;
|
||||
|
||||
const Environment = imports.ui.environment;
|
||||
const { TransientSignalHolder, registerDestroyableType } = imports.misc.signalTracker;
|
||||
|
|
@ -17,14 +17,11 @@ const Destroyable = GObject.registerClass({
|
|||
}, class Destroyable extends GObject.Object {});
|
||||
registerDestroyableType(Destroyable);
|
||||
|
||||
class PlainEmitter {}
|
||||
Signals.addSignalMethods(PlainEmitter.prototype);
|
||||
|
||||
const GObjectEmitter = GObject.registerClass({
|
||||
Signals: { 'signal': {} },
|
||||
}, class GObjectEmitter extends Destroyable {});
|
||||
|
||||
const emitter1 = new PlainEmitter();
|
||||
const emitter1 = new Signals.EventEmitter();
|
||||
const emitter2 = new GObjectEmitter();
|
||||
|
||||
const tracked1 = new Destroyable();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue