JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q27967F
  • License MIT

minimal tiny and performant event emitter / dispatcher

Package Exports

  • micromitter

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 (micromitter) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

micromitter

minimal and performant event emitter / emitter with custom events and payload

Usage

create instance

import Emitter from 'micromitter';

const emitter = new Emitter();

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

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

use global instance

import {emitter} from 'micromitter';

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

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

use decorator

import { micromitter } from 'micromitter';

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

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

const tt = new Tester();

tt.on('test', tt.onTest);
tt.emit('test', {foo:'bar'});