... | @@ -18,41 +18,18 @@ box.y_align = Big.BoxAlignment.CENTER; |
... | @@ -18,41 +18,18 @@ box.y_align = Big.BoxAlignment.CENTER; |
|
|
|
|
|
### Signals
|
|
### Signals
|
|
|
|
|
|
Every object inherited from GObject has a "connect" method. Example:
|
|
Every object inherited from GObject has `connect()`, `disconnect()` and `emit()` methods. Example:
|
|
|
|
|
|
```js
|
|
```js
|
|
actor.connect('button-press-event', function (actor, event) {
|
|
let handlerId = actor.connect('button-press-event', function (actor, event) {
|
|
...
|
|
...
|
|
});
|
|
});
|
|
```
|
|
|
|
|
|
|
|
**NOTE:** GJS also includes the `signals` import for applying signals to native classes:
|
|
|
|
|
|
|
|
```js
|
|
actor.disconnect(handlerId);
|
|
const Signals = imports.signals;
|
|
|
|
|
|
|
|
var MyJSClass = class {
|
|
|
|
testSignalEmission () {
|
|
|
|
this.emit("exampleSignal");
|
|
|
|
this.emit("exampleSignal2", "stringArg", 42);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Signals.addSignalMethods(MyJSClass.prototype);
|
|
|
|
|
|
|
|
let obj = new MyJSObject();
|
|
|
|
let handlerId = obj.connect("exampleSignal", () => log("exampleSignal emitted"));
|
|
|
|
obj.connect("exampleSignal2", (stringArg, intArg) => {
|
|
|
|
log(stringArg);
|
|
|
|
log(intArg);
|
|
|
|
});
|
|
|
|
|
|
|
|
obj.testSignalEmission();
|
|
|
|
|
|
|
|
// Disconnecting signals by id or all at once
|
|
|
|
obj.disconnect(handlerId);
|
|
|
|
obj.disconnectAll();
|
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
**NOTE:** GJS also includes a built-in [`signals`](Modules#signals) module for applying signals to native JavaScript classes.
|
|
|
|
|
|
## Enumerations and Flags
|
|
## Enumerations and Flags
|
|
|
|
|
|
Both enumerations and flags appear as entries under the namespace, with associated member properties. Example:
|
|
Both enumerations and flags appear as entries under the namespace, with associated member properties. Example:
|
... | | ... | |