JSPM

microdispatch

1.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q31085F
  • License MIT

minimal event dispatcher / emitter

Package Exports

  • microdispatch

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (microdispatch) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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'});