npm mitt 2.1.0

latest releases: 3.0.1, 3.0.0
4 years ago

Mitt 2 is out of preview!

  • It's written in TypeScript and ships type definitions (#107, thanks again @jackfranklin!)

  • Event handlers are now stored in a Map instead of an Object.

    Upgrading: If you aren't passing an object to mitt({}), version 2 is backwards-compatible.
    If you were, turn your object into a map:

    -const handlers = {
    -  foo: [() => alert(1)]
    -};
    +const handlers = new Map();
    +handlers.set('foo', [() => alert(1)]);
    
    const events = mitt(handlers);
  • The event handler Map is now exposed as .all: (#105, thanks @jaylinski!)

    const events = mitt();
    events.on('foo', () => alert(1));
    events.on('bar', () => alert(2));
    
    // access handlers directly if needed:
    events.all.get('foo') // [() => alert(1)]
    
    // remove all event handlers:
    events.all.clear();

Don't miss a new mitt release

NewReleases is sending notifications on new releases.