aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Miller <[email protected]>2023-07-04 13:28:29 -0400
committerJason Miller <[email protected]>2023-07-04 13:28:29 -0400
commit05f4ce67e8f13002ee7229031d583091d24488a0 (patch)
tree1acadb34fac42022dd9e78fd119f112bd04acb9b
parent3f81679127be71dd7ad1b2bbbd5a56df81c96290 (diff)
apply prettier formatting to all files
-rw-r--r--src/index.ts20
-rw-r--r--test/index_test.ts16
2 files changed, 16 insertions, 20 deletions
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<T = Record<string, unknown>> = (
// An array of all currently registered event handlers for a type
export 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<
@@ -24,11 +26,16 @@ export interface Emitter<Events extends Record<EventType, unknown>> {
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;
}
/**
@@ -45,7 +52,6 @@ export default function mitt<Events extends Record<EventType, unknown>>(
all = all || new Map();
return {
-
/**
* A Map of event names to registered handler functions.
*/
@@ -61,8 +67,7 @@ export default function mitt<Events extends Record<EventType, unknown>>(
const handlers: Array<GenericEventHandler> | undefined = all!.get(type);
if (handlers) {
handlers.push(handler);
- }
- else {
+ } else {
all!.set(type, [handler] as EventHandlerList<Events[keyof Events]>);
}
},
@@ -79,8 +84,7 @@ export default function mitt<Events extends Record<EventType, unknown>>(
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', () => {