Class Notifier<T>

Notifier

Description

A class for creating events

Export

Notifier

Type Parameters

  • T = void

Constructors

Properties

callbacks: CallbackDescription[] = []
errorFns: CallbackDescription[] = []
refCount: number = 0

Methods

  • Trigger the error event event

    Parameters

    • value: Error

      The value to pass to the callback

    Returns void

    void

    Example

    const event = new Notifier<number>();
    const id = event.subscribe((value:number) => {
    console.log(value);
    }, (error) => {
    console.error(error);
    });
    event.error(new Error("It doesnt't work!"));
    event.unsubscribe(id);
  • Trigger the event

    Parameters

    • value: T

      The value to pass to the callback

    Returns void

    void

    Example

    const event = new Notifier<number>();
    const id = event.subscribe((value:number) => {
    console.log(value);
    });
    event.notify(1);
    event.unsubscribe(id);

    Deprecated

    Use notify instead

  • Trigger the event

    Parameters

    • value: T

      The value to pass to the callback

    Returns void

    void

    Example

    const event = new Notifier<number>();
    const id = event.subscribe((value:number) => {
    console.log(value);
    });
    event.notify(1);
    event.unsubscribe(id);
  • Subscribe to the event

    Parameters

    • callback: ((value) => void)

      The callback to call when the event is triggered

        • (value): void
        • Parameters

          • value: T

          Returns void

    • Optional error: ((value) => void)

      The callback to call when an error is triggered

        • (value): void
        • Parameters

          • value: Error

          Returns void

    Returns number

    The id of the subscription

    Example

    const event = new Notifier<number>();
    const id = event.subscribe((value:number) => {
    console.log(value);
    });
    event.notify(1);
    event.unsubscribe(id);
  • Convert the event to a promise

    Returns Promise<T>

    Promise

    Description

    Convert the event to a promise. This is useful for the async/await style async pattern.

    Example

    async myFunction() {
    const result=await WebzDialog.popup(
    "Hello World",
    "Alert", ["Ok","Cancel"]).toPromise();
    console.log(result);
    }
  • Unsubscribe from the event

    Parameters

    • id: number

      The id of the subscription to remove

    Returns void

    void

    Example

    const event = new Notifier<number>();
    const id = event.subscribe((value:number) => {
    console.log(value);
    });
    event.notify(1);
    event.unsubscribe(id);

Generated using TypeDoc