Skip to content

Commit ec9122b

Browse files
committed
Fix the format and update the off API
1 parent 5f2ccef commit ec9122b

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ Register an event handler for the given type.
132132
### off
133133

134134
Remove an event handler for the given type.
135+
If omit the `handler`, all event handlers of the given type are deleted.
135136

136137
#### Parameters
137138

src/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,20 @@ export default function mitt(all?: EventHandlerMap): Emitter {
5656

5757
/**
5858
* Remove an event handler for the given type.
59+
* If omit the `handler`, all event handlers of the given type are deleted.
5960
* @param {string|symbol} type Type of event to unregister `handler` from, or `"*"`
6061
* @param {Function} handler Handler function to remove
6162
* @memberOf mitt
6263
*/
6364
off<T = any>(type: EventType, handler?: Handler<T>) {
6465
const handlers = all.get(type);
6566
if (handlers) {
66-
if(handler){
67-
handlers.splice(handlers.indexOf(handler) >>> 0, 1);
68-
} else {
69-
all.delete(type);
70-
}
67+
if (handler) {
68+
handlers.splice(handlers.indexOf(handler) >>> 0, 1);
69+
}
70+
else {
71+
all.delete(type);
72+
}
7173
}
7274
},
7375

0 commit comments

Comments
 (0)