@lumino/signaling

  • Version 1.11.0
  • Published
  • 156 kB
  • 2 dependencies
  • BSD-3-Clause license

Install

npm i @lumino/signaling
yarn add @lumino/signaling
pnpm add @lumino/signaling

Overview

Lumino Signals and Slots

Index

Classes

class Signal

class Signal<T, U> implements ISignal<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

constructor

constructor(sender: {});
  • Construct a new signal.

    Parameter sender

    The sender which owns the signal.

property sender

readonly sender: {};
  • The sender which owns the signal.

method block

block: (fn: () => void) => void;
  • Block the signal during the execution of a callback.

    ### Notes The callback function must be synchronous.

    Parameter fn

    The callback during which the signal is blocked

method connect

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

    Parameter slot

    The slot to invoke when the signal is emitted.

    Parameter thisArg

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

    Returns

    true if the connection succeeds, false otherwise.

method disconnect

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

    Parameter slot

    The slot to disconnect from the signal.

    Parameter thisArg

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

    Returns

    true if the connection is removed, false otherwise.

method emit

emit: (args: U) => void;
  • Emit the signal and invoke the connected slots.

    Parameter args

    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.

Interfaces

interface ISignal

interface ISignal<T, U> {}
  • An object used for type-safe inter-object communication.

    #### Notes Signals provide a type-safe implementation of the publish-subscribe pattern. An object (publisher) declares which signals it will emit, and consumers connect callbacks (subscribers) to those signals. The subscribers are invoked whenever the publisher emits the signal.

method block

block: (fn: () => void) => void;
  • Block the signal during the execution of a callback.

    ### Notes The callback function must be synchronous.

    Parameter fn

    The callback during which the signal is blocked

method connect

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

    Parameter slot

    The slot to invoke when the signal is emitted.

    Parameter thisArg

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

    Returns

    true if the connection succeeds, false otherwise.

    #### Notes Slots are invoked in the order in which they are connected.

    Signal connections are unique. If a connection already exists for the given slot and thisArg, this method returns false.

    A newly connected slot will not be invoked until the next time the signal is emitted, even if the slot is connected while the signal is dispatching.

method disconnect

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

    Parameter slot

    The slot to disconnect from the signal.

    Parameter thisArg

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

    Returns

    true if the connection is removed, false otherwise.

    #### Notes If no connection exists for the given slot and thisArg, this method returns false.

    A disconnected slot will no longer be invoked, even if the slot is disconnected while the signal is dispatching.

Type Aliases

type Slot

type Slot<T, U> = (sender: T, args: U) => void;
  • A type alias for a slot function.

    Parameter sender

    The object emitting the signal.

    Parameter args

    The args object emitted with the signal.

    #### Notes A slot is invoked when a signal to which it is connected is emitted.

Namespaces

namespace Signal

namespace Signal {}
  • The namespace for the Signal class statics.

function blockAll

blockAll: (sender: unknown, fn: () => void) => void;
  • Block all signals emitted by an object during the execution of a callback.

    ### Notes The callback function must be synchronous.

    Parameter sender

    The signals sender

    Parameter fn

    The callback during which all signals are blocked

function clearData

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

    Parameter object

    The object for which the data should be cleared.

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

function disconnectAll

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

    Parameter object

    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.

function disconnectBetween

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

    Parameter sender

    The sender object of interest.

    Parameter receiver

    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.

function disconnectReceiver

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

    Parameter receiver

    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.

function disconnectSender

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

    Parameter sender

    The sender object of interest.

function getExceptionHandler

getExceptionHandler: () => ExceptionHandler;
  • Get the signal exception handler.

    Returns

    The current exception handler.

    #### Notes The default exception handler is console.error.

function setExceptionHandler

setExceptionHandler: (handler: ExceptionHandler) => ExceptionHandler;
  • Set the signal exception handler.

    Parameter handler

    The function to use as the exception handler.

    Returns

    The old exception handler.

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

type ExceptionHandler

type ExceptionHandler = (err: Error) => void;
  • A type alias for the exception handler function.

Package Files (1)

Dependencies (2)

Dev Dependencies (22)

Peer Dependencies (0)

No peer dependencies.

Badge

To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@lumino/signaling.

  • Markdown
    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@lumino/signaling)
  • HTML
    <a href="https://www.jsdocs.io/package/@lumino/signaling"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>