Nachos Preventing Motivation

    run-notifier
    TypeScript icon, indicating that this package has built-in type declarations

    1.1.3 • Public • Published

    run-notifier

    npm version license downloads

    Allows you to notify listeners.

    Install with npm:

    npm:

    npm install run-notifier --save

    How to use

    import {Notifier} from "run-notifier";
    
    const listener1 = (params: string) => console.log('listener 1.', params);
    const listener2 = (params: string) => console.log('listener 2.', params);
    
    const notifier: Notifier<string> = new Notifier();
    
    notifier.addListener(listener1);
    notifier.addListener(listener2);
    notifier.signal('test A');
    // console --->>> listener 1. test A
    // console --->>> listener 2. test A
    notifier.removeListener(listener1);
    notifier.removeListener(listener2);
    
    // or
    
    notifier.addListener('listener1', listener1);
    notifier.addListener('listener2', listener2);
    notifier.signal('test B');
    // console --->>> listener 1. test B
    // console --->>> listener 2. test B
    notifier.removeListener('listener1');
    notifier.removeListener('listener2');
    
    // or
    
    notifier.addListener('listener1', listener2);
    notifier.addListener('listener1', listener1); // replace listener with same key
    notifier.addListener('listener2', listener2);
    notifier.signal('test C');
    // console --->>> listener 1. test C
    // console --->>> listener 2. test C
    notifier.removeListener('listener1');
    notifier.removeListener('listener2');

    Doc

    /**
     * Notifier. Allows you to notify listeners.
     */
    class Notifier<Params> {
        /**
         * Called before adding the first notification listener.
         * Used to initialize any activity in inheritor.
         */
        protected onStart(): void;
    
        /**
         * Called after removing the last notification listener.
         * Used to finalize any activity in inheritor.
         */
        protected onStop(): void;
    
        /**
         * Add notification listener.
         *
         * @param listener Listener;
         * @param notice Handler. Called on listener notification;
         * @param extra Additional arguments.
         */
        public addListener(listener: NotifierListener<Params>, notice?: NotifierNotice<Params>, ...extra: any): void;
    
        /**
         * Remove all notification listeners.
         */
        public clear(): void;
    
        /**
         * Remove notification listener.
         *
         * @param listener Listener.
         */
        public removeListener(listener: NotifierListener<Params>): void;
    
        /**
         * Notify listeners.
         *
         * @param params Notification parameters.
         */
        public signal(params: Params): void;
    }

    License

    MIT. Copyright (c) 2021 Vitaliy Dyukar.

    Install

    npm i run-notifier

    DownloadsWeekly Downloads

    0

    Version

    1.1.3

    License

    MIT

    Unpacked Size

    6.32 kB

    Total Files

    4

    Last publish

    Collaborators

    • vitaliy.du