Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including microdispatch with all npm packages installed. Try it out:

var microdispatch = require("microdispatch")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

microdispatch v1.2.0

minimal event dispatcher / emitter

Build Status

MicroDispatcher

minimal and performant event dispatcher / emitter supporting custom event objects

Usage

create instance

import MicroDispatch from 'microdispatch';

const micro = new MicroDispatch();

micro.on('test', (e)=>{
  console.log(e.type === 'test');
  console.log(e.foo === 'bar');
});

micro.dispatch('test', {foo:'bar'});

use global instance

import {dispatcher} from 'microdispatch';

dispatcher.on('test', (e)=>{
  console.log(e.type === 'test');
  console.log(e.foo === 'bar');
});

dispatcher.emit('test', {foo:'bar'});

use decorator

import {microdispatch} from 'microdispatch';

//v1: use es7 decorators
@microdispatch
class Tester {
    onTest(e){
        console.log(e.type === 'test');
        console.log(e.foo === 'bar');
    }
}

//v2 use the decorator as a function
microdispatch(Tester);

const tt = new Tester();

tt.on('test', tt.onTest);
tt.dispatch('test', {foo:'bar'});
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free