Necessitates Proper Modularity

    @chickendinosaur/eventemitter

    11.0.2 • Public • Published

    Slings events.


    Author

    John Pittman
    john@chickendinosaur.com

    Getting Started

    Installation

    npm

    npm install @chickendinosaur/eventemitter

    Usage

    Event

    import Event from '@chickendinosaur/eventemitter/Event';
    
    const pauseEvent = new Event('pause');
    pauseEvent.target = window || this;
    
    pauseEvent.dispose();
    
    pauseEvent.init('pause');
    pauseEvent.target = window || this;

    EventEmitter

    import EventEmitter from '@chickendinosaur/eventemitter';
    import Event from '@chickendinosaur/eventemitter/Event.js';
    
    class ComicEvent extends Event {
    	constructor(type) {
    		super(type);
    
    		this.superhero = 'The Nameless Man';
    		this.sidekick = null;
    	}
    }
    
    const eventemitter = new EventEmitter();
    
    const comicEvent = new ComicEvent('comic');
    comicEvent.superhero = 'Batman';
    comicEvent.sidekick = 'Robin';
    
    eventemitter.addEventListener('comic', function (event) {
    	console.log(`Callback scope: ${this.constructor.name}`);
    	console.log(`Event: ${event.type}`);
    	console.log(`${event.superhero} (POW!), ${event.sidekick} (BOOM!)`);
    });
    
    // Ability pipe all events to a listener.
    eventemitter.pipe(function (event) {
    	if (event.type === 'comic') {
    		console.log(`Piped the ${event.type} event.`);
    	}
    });
    
    console.log(`Listener count: ${eventemitter.getEventListenerCount('comic')}`);
    console.log(`Piped listener count: ${eventemitter.getPipedEventListenerCount()}`);
    
    // triggerEvent is meant to take an Event object which should be extended
    // for a custom event or at least contain a 'type' property.
    
    eventemitter.triggerEvent(comicEvent);
    
    eventemitter.removeAllEventListeners('comic');
    eventemitter.triggerEvent(comicEvent);
    
    eventemitter.unpipeAll();
    eventemitter.triggerEvent(comicEvent);

    Development

    Installation

    From the project root:

    • npm install
    • npm run build

    Commands

    Local

    npm run:

    build, clean, compile, help, init, start, test, compress, publish, update, documentation, set-access, set-author, set-description, set-dist, set-global, set-keywords, set-license, set-main, set-name, set-private, set-repository, set-src, set-test, set-version


    License

    The MIT License (MIT)

    Copyright (c) 2016 John Pittman

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

    Install

    npm i @chickendinosaur/eventemitter

    DownloadsWeekly Downloads

    0

    Version

    11.0.2

    License

    MIT

    Last publish

    Collaborators

    • chickendinosaur