Skip to content

Instantly share code, notes, and snippets.

@buzztaiki
Created December 14, 2021 08:50
Show Gist options
  • Save buzztaiki/f5322e88808dc3b4b7039707745d4765 to your computer and use it in GitHub Desktop.
Save buzztaiki/f5322e88808dc3b4b7039707745d4765 to your computer and use it in GitHub Desktop.
// see https://gitlab.gnome.org/GNOME/gjs/blob/master/doc/Modules.md#signals
const Signals = imports.signals;
class MyJSClass {
testSignalEmission () {
this.emit("example-signal", "moo", 42);
}
}
Signals.addSignalMethods(MyJSClass.prototype);
const obj = new MyJSClass();
const handlerId = obj.connect("example-signal", (_obj, a, b) => {
print("handler1", a, b);
});
obj.connect("example-signal", (_obj, a, b) => {
print("handler2", a, b);
});
obj.testSignalEmission();
obj.disconnect(handlerId);
obj.testSignalEmission();
obj.disconnectAll();
@buzztaiki
Copy link
Author

$ gjs gjs-signals-example.js 
handler1 moo 42
handler2 moo 42
handler2 moo 42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment