apply prettier formatting to all files
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Jason Miller · committed by Jason Miller · parent 3f81679 · Browse files · 2 files·+16 added−20 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+16 added−20 removed
- tests:+4 added−12 removed
- other:+12 added−8 removed
Provenance
- Commit
05f4ce6- Tree
1acadb3- Author
Jason Miller <jason@developit.ca>- Committer
Jason Miller <jason@developit.ca>- Parent
3f81679
2 files changed+16 added−20 removed
modified:src/index.ts+12 added-8 removed
8 unmodified lines910111213131415161718195 unmodified lines25262728272930313233343531363738394041428 unmodified lines5152535448555657587 unmodified lines66676869646570717273748 unmodified lines838485868283878889909132 unmodified lines8 unmodified lines) => void;
// An array of all currently registered event handlers for a typeexport type EventHandlerList<T = unknown> = Array<Handler<T>>;export type WildCardEventHandlerList<T = Record<string, unknown>> = Array<WildcardHandler<T>>;export type WildCardEventHandlerList<T = Record<string, unknown>> = Array< WildcardHandler<T>>;
// A map of event types and their corresponding event handlers.export type EventHandlerMap<Events extends Record<EventType, unknown>> = Map< keyof Events | '*',5 unmodified lines
on<Key extends keyof Events>(type: Key, handler: Handler<Events[Key]>): void; on(type: '*', handler: WildcardHandler<Events>): void;
off<Key extends keyof Events>(type: Key, handler?: Handler<Events[Key]>): void; off<Key extends keyof Events>( type: Key, handler?: Handler<Events[Key]> ): void; off(type: '*', handler: WildcardHandler<Events>): void;
emit<Key extends keyof Events>(type: Key, event: Events[Key]): void; emit<Key extends keyof Events>(type: undefined extends Events[Key] ? Key : never): void; emit<Key extends keyof Events>( type: undefined extends Events[Key] ? Key : never ): void;}
/** * Mitt: Tiny (~200b) functional event emitter / pubsub.8 unmodified lines | WildcardHandler<Events>; all = all || new Map();
return {
/** * A Map of event names to registered handler functions. */ all,7 unmodified lines on<Key extends keyof Events>(type: Key, handler: GenericEventHandler) { const handlers: Array<GenericEventHandler> | undefined = all!.get(type); if (handlers) { handlers.push(handler); } else { } else { all!.set(type, [handler] as EventHandlerList<Events[keyof Events]>); } },
8 unmodified lines const handlers: Array<GenericEventHandler> | undefined = all!.get(type); if (handlers) { if (handler) { handlers.splice(handlers.indexOf(handler) >>> 0, 1); } else { } else { all!.set(type, []); } } },32 unmodified linesmodified:test/index_test.ts+4 added-12 removed
42 unmodified lines43 });44 45 describe('properties', () => {46 it('should expose the event handler map', () => {47- expect(inst)48- .to.have.property('all')49- .that.is.a('map');47+ expect(inst).to.have.property('all').that.is.a('map');48 });49 });50 51 describe('on()', () => {52 it('should be a function', () => {55- expect(inst)56- .to.have.property('on')57- .that.is.a('function');53+ expect(inst).to.have.property('on').that.is.a('function');54 });55 56 it('should register handler for new type', () => {57 const foo = () => {};48 unmodified lines106 });107 108 describe('off()', () => {109 it('should be a function', () => {114- expect(inst)115- .to.have.property('off')116- .that.is.a('function');110+ expect(inst).to.have.property('off').that.is.a('function');111 });112 113 it('should remove handler for type', () => {114 const foo = () => {};43 unmodified lines158 });159 160 describe('emit()', () => {161 it('should be a function', () => {168- expect(inst)169- .to.have.property('emit')170- .that.is.a('function');162+ expect(inst).to.have.property('emit').that.is.a('function');163 });164 165 it('should invoke handler for type', () => {166 const event = { a: 'b' };38 unmodified lines