Never Post Memes

    tiny-events

    1.0.1 • Public • Published

    tiny-events Build Status Coverage Status

    Sauce Test Status

    A very tiny (400b) EventEmitter implementation for client- and server-side code.

    installation

    npm install --save tiny-events

    usage

    instantiate the object directly..

    // import the module
    var EventEmitter = require('tiny-events').EventEmitter;
     
    // instantiate the object
    var events = new EventEmitter();
     
    // listen to 'foo' events
    events.on('foo', function (data) {
        console.log('foo occured!');
    });
     
    // emit a 'foo' event
    events.emit('foo');
     
    // emit a 'foo' event with some data
    events.emit('foo', 'hello world');
     
    // remove all foo event listeners
    events.off('foo');

    ... or subclass it.

    var utils = require('utils');
    var EventEmitter = require('tiny-events').EventEmitter;
     
    function MyClass() {
        EventEmitter.call(this);
    }
     
    util.inherits(MyClass, EventEmitter);

    API

    • on(type: string, listener: Function): EventEmitter
    • once(type: string, listener: Function): EventEmitter
    • off(type: string, listener?: Function): EventEmitter
    • emit(type: string, ...args: any[]): EventEmitter

    Install

    npm i tiny-events

    DownloadsWeekly Downloads

    1,983

    Version

    1.0.1

    License

    MIT

    Last publish

    Collaborators

    • zaubernerd