Skip to content

2.1.0

Compare
Choose a tag to compare
@developit developit released this 15 Jul 15:04

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();