Interface

Gjsgjs/gjsSignalMethods

You can use the Signals.addSignalMethods method to apply the Signals convenience methods to an Object. Generally, this is called on an object prototype, but may also be called on an object instance. You can use this Interface for this object or prototype to make the methods in typescript known

const Signals = imports.signals;

// Define an interface with the same name of your class to make the methods known
interface Events extends Signals.Methods {}

class Events {}
Signals.addSignalMethods(Events.prototype);

const events = new Events();

// Typescript will not complain here
events.emit("test-signal", "test argument");
interface SignalMethods {
    connect(
        sigName: string,
        callback: (self: any, ...args: any[]) => void,
    ): number;
    disconnect(id: number): void;
    disconnectAll(): void;
    emit(sigName: string, ...args: any[]): void;
    signalHandlerIsConnected(id: number): boolean;
}
Index

Methods

  • Connects a callback to a signal for an object. Pass the returned ID to disconnect() to remove the handler.

    If callback returns true, emission will stop and no other handlers will be invoked.

    Warning: Unlike GObject signals, this within a signal callback will always refer to the global object (ie. globalThis).

    Parameters

    • sigName: string

      A signal name

    • callback: (self: any, ...args: any[]) => void

      A callback function

    Returns number

    A handler ID

  • Disconnects a handler for a signal.

    Parameters

    • id: number

      The ID of the handler to be disconnected

    Returns void

  • Disconnects all signal handlers for an object.

    Returns void

  • Emits a signal for an object. Emission stops if a signal handler returns true.

    Unlike GObject signals, it is not necessary to declare signals or define their signature. Simply call emit() with whatever signal name you wish, with whatever arguments you wish.

    Parameters

    • sigName: string

      A signal name

    • ...args: any[]

      Any number of arguments, of any type

    Returns void

  • Checks if a handler ID is connected.

    Parameters

    • id: number

      The ID of the handler to be disconnected

    Returns boolean

    true if connected, or false if not