aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsealice <[email protected]>2021-01-11 20:20:51 +0800
committersealice <[email protected]>2021-01-11 20:20:51 +0800
commitec9122bba89372f521da8c2ae4febb40ded3c570 (patch)
tree9dd4b2558e1fbc38419f297026a51f3d1d64a6ae
parent5f2ccef47bb1d8656433b529573212273b82bf83 (diff)
Fix the format and update the off API
-rw-r--r--README.md1
-rw-r--r--src/index.ts12
2 files changed, 8 insertions, 5 deletions
diff --git a/README.md b/README.md
index 08a21bf..9bc0436 100644
--- a/README.md
+++ b/README.md
@@ -132,6 +132,7 @@ Register an event handler for the given type.
### off
Remove an event handler for the given type.
+If omit the `handler`, all event handlers of the given type are deleted.
#### Parameters
diff --git a/src/index.ts b/src/index.ts
index 394a5ed..946802a 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -56,6 +56,7 @@ export default function mitt(all?: EventHandlerMap): Emitter {
/**
* Remove an event handler for the given type.
+ * If omit the `handler`, all event handlers of the given type are deleted.
* @param {string|symbol} type Type of event to unregister `handler` from, or `"*"`
* @param {Function} handler Handler function to remove
* @memberOf mitt
@@ -63,11 +64,12 @@ export default function mitt(all?: EventHandlerMap): Emitter {
off<T = any>(type: EventType, handler?: Handler<T>) {
const handlers = all.get(type);
if (handlers) {
- if(handler){
- handlers.splice(handlers.indexOf(handler) >>> 0, 1);
- } else {
- all.delete(type);
- }
+ if (handler) {
+ handlers.splice(handlers.indexOf(handler) >>> 0, 1);
+ }
+ else {
+ all.delete(type);
+ }
}
},