Class Signal<T, U>

A concrete implementation of ISignal.

Example

import { ISignal, Signal } from '@lumino/signaling';

class SomeClass {

constructor(name: string) {
this.name = name;
}

readonly name: string;

get valueChanged: ISignal<this, number> {
return this._valueChanged;
}

get value(): number {
return this._value;
}

set value(value: number) {
if (value === this._value) {
return;
}
this._value = value;
this._valueChanged.emit(value);
}

private _value = 0;
private _valueChanged = new Signal<this, number>(this);
}

function logger(sender: SomeClass, value: number): void {
console.log(sender.name, value);
}

let m1 = new SomeClass('foo');
let m2 = new SomeClass('bar');

m1.valueChanged.connect(logger);
m2.valueChanged.connect(logger);

m1.value = 42; // logs: foo 42
m2.value = 17; // logs: bar 17

Type Parameters

  • T

  • U

Hierarchy

Implements

Constructors

Properties

Methods

Constructors

Properties

sender: T

The sender which owns the signal.

Methods

  • Connect a slot to the signal.

    Parameters

    • slot: Slot<T, U>

      The slot to invoke when the signal is emitted.

    • Optional thisArg: unknown

      The this context for the slot. If provided, this must be a non-primitive object.

    Returns boolean

    true if the connection succeeds, false otherwise.

  • Disconnect a slot from the signal.

    Parameters

    • slot: Slot<T, U>

      The slot to disconnect from the signal.

    • Optional thisArg: unknown

      The this context for the slot. If provided, this must be a non-primitive object.

    Returns boolean

    true if the connection is removed, false otherwise.

  • Emit the signal and invoke the connected slots.

    Parameters

    • args: U

      The args to pass to the connected slots.

      Notes

      Slots are invoked synchronously in connection order.

      Exceptions thrown by connected slots will be caught and logged.

    Returns void

Generated using TypeDoc