Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Signal<T, U>

A concrete implementation of ISignal. The namespace for the Signal class statics.

Example

import { ISignal, Signal } from '@phosphor/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

  • Signal

Implements

Index

Type aliases

Static ExceptionHandler

ExceptionHandler: function

A type alias for the exception handler function.

Type declaration

    • (err: Error): void
    • Parameters

      • err: Error

      Returns void

Constructors

constructor

  • new Signal(sender: T): Signal
  • Construct a new signal.

    Parameters

    • sender: T

      The sender which owns the signal.

    Returns Signal

Properties

sender

sender: T

The sender which owns the signal.

Methods

connect

  • connect(slot: Slot<T, U>, thisArg?: any): boolean
  • Connect a slot to the signal.

    Parameters

    • slot: Slot<T, U>

      The slot to invoke when the signal is emitted.

    • Optional thisArg: any

      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

  • disconnect(slot: Slot<T, U>, thisArg?: any): boolean
  • Disconnect a slot from the signal.

    Parameters

    • slot: Slot<T, U>

      The slot to disconnect from the signal.

    • Optional thisArg: any

      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

  • emit(args: U): void
  • 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

Static clearData

  • clearData(object: any): void
  • Clear all signal data associated with the given object.

    Parameters

    • object: any

      The object for which the data should be cleared.

      Notes

      This removes all signal connections and any other signal data associated with the object.

    Returns void

Static disconnectAll

  • disconnectAll(object: any): void
  • Remove all connections where an object is the sender or receiver.

    Parameters

    • object: any

      The object of interest.

      Notes

      If a thisArg is provided when connecting a signal, that object is considered the receiver. Otherwise, the slot is considered the receiver.

    Returns void

Static disconnectBetween

  • disconnectBetween(sender: any, receiver: any): void
  • Remove all connections between a sender and receiver.

    Parameters

    • sender: any

      The sender object of interest.

    • receiver: any

      The receiver object of interest.

      Notes

      If a thisArg is provided when connecting a signal, that object is considered the receiver. Otherwise, the slot is considered the receiver.

    Returns void

Static disconnectReceiver

  • disconnectReceiver(receiver: any): void
  • Remove all connections where the given object is the receiver.

    Parameters

    • receiver: any

      The receiver object of interest.

      Notes

      If a thisArg is provided when connecting a signal, that object is considered the receiver. Otherwise, the slot is considered the receiver.

    Returns void

Static disconnectSender

  • disconnectSender(sender: any): void
  • Remove all connections where the given object is the sender.

    Parameters

    • sender: any

      The sender object of interest.

    Returns void

Static getExceptionHandler

  • Get the signal exception handler.

    Returns ExceptionHandler

    The current exception handler.

    Notes

    The default exception handler is console.error.

Static setExceptionHandler

  • Set the signal exception handler.

    Parameters

    Returns ExceptionHandler

    The old exception handler.

    Notes

    The exception handler is invoked when a slot throws an exception.

Generated using TypeDoc