Skip to content

Commit

Permalink
Fix the format and update the off API
Browse files Browse the repository at this point in the history
  • Loading branch information
sealice committed Jan 11, 2021
1 parent 5f2ccef commit ec9122b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 7 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,20 @@ 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
*/
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);
}
}
},

Expand Down

0 comments on commit ec9122b

Please sign in to comment.