diff --git a/src/index.ts b/src/index.ts index 7301520..17672aa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,7 +10,9 @@ export type WildcardHandler> = ( // An array of all currently registered event handlers for a type export type EventHandlerList = Array>; -export type WildCardEventHandlerList> = Array>; +export type WildCardEventHandlerList> = Array< + WildcardHandler +>; // A map of event types and their corresponding event handlers. export type EventHandlerMap> = Map< @@ -24,11 +26,16 @@ export interface Emitter> { on(type: Key, handler: Handler): void; on(type: '*', handler: WildcardHandler): void; - off(type: Key, handler?: Handler): void; + off( + type: Key, + handler?: Handler + ): void; off(type: '*', handler: WildcardHandler): void; emit(type: Key, event: Events[Key]): void; - emit(type: undefined extends Events[Key] ? Key : never): void; + emit( + type: undefined extends Events[Key] ? Key : never + ): void; } /** @@ -45,7 +52,6 @@ export default function mitt>( all = all || new Map(); return { - /** * A Map of event names to registered handler functions. */ @@ -61,8 +67,7 @@ export default function mitt>( const handlers: Array | undefined = all!.get(type); if (handlers) { handlers.push(handler); - } - else { + } else { all!.set(type, [handler] as EventHandlerList); } }, @@ -79,8 +84,7 @@ export default function mitt>( if (handlers) { if (handler) { handlers.splice(handlers.indexOf(handler) >>> 0, 1); - } - else { + } else { all!.set(type, []); } } diff --git a/test/index_test.ts b/test/index_test.ts index 723dfa6..31c9495 100644 --- a/test/index_test.ts +++ b/test/index_test.ts @@ -44,17 +44,13 @@ describe('mitt#', () => { describe('properties', () => { it('should expose the event handler map', () => { - expect(inst) - .to.have.property('all') - .that.is.a('map'); + expect(inst).to.have.property('all').that.is.a('map'); }); }); describe('on()', () => { it('should be a function', () => { - expect(inst) - .to.have.property('on') - .that.is.a('function'); + expect(inst).to.have.property('on').that.is.a('function'); }); it('should register handler for new type', () => { @@ -111,9 +107,7 @@ describe('mitt#', () => { describe('off()', () => { it('should be a function', () => { - expect(inst) - .to.have.property('off') - .that.is.a('function'); + expect(inst).to.have.property('off').that.is.a('function'); }); it('should remove handler for type', () => { @@ -165,9 +159,7 @@ describe('mitt#', () => { describe('emit()', () => { it('should be a function', () => { - expect(inst) - .to.have.property('emit') - .that.is.a('function'); + expect(inst).to.have.property('emit').that.is.a('function'); }); it('should invoke handler for type', () => {