diff options
| author | tunnckoCore <[email protected]> | 2017-01-17 19:13:41 +0200 |
|---|---|---|
| committer | tunnckoCore <[email protected]> | 2017-01-17 19:13:41 +0200 |
| commit | e7c222c0e840b34eb56566da453d7a12a257c61f (patch) | |
| tree | 784bfbf1f45ff70e83835305f0d857775349d710 /src | |
| parent | 8b4f2defd7fca02674a45d89900557a6a4b5e5c3 (diff) | |
add editorconfig, fix original identation
Diffstat (limited to 'src')
| -rw-r--r-- | src/index.js | 96 |
1 files changed, 48 insertions, 48 deletions
diff --git a/src/index.js b/src/index.js index 5140057..5e11237 100644 --- a/src/index.js +++ b/src/index.js @@ -3,57 +3,57 @@ * @returns {Mitt} */ export default function mitt () { - let ret = { - all: Object.create(null), + let ret = { + all: Object.create(null), - /** - * Register an event handler for the given type. - * - * @param {String} type Type of event to listen for, or `"*"` for all events - * @param {Function} handler Function to call in response to given event - * @return {Object} the `mitt` instance for chaining - * @memberOf mitt - */ - on(type, handler) { - list(type).add(handler); - return ret; - }, + /** + * Register an event handler for the given type. + * + * @param {String} type Type of event to listen for, or `"*"` for all events + * @param {Function} handler Function to call in response to given event + * @return {Object} the `mitt` instance for chaining + * @memberOf mitt + */ + on(type, handler) { + list(type).add(handler); + return ret; + }, - /** - * Remove an event handler for the given type. - * - * @param {String} type Type of event to unregister `handler` from, or `"*"` - * @param {Function} handler Handler function to remove - * @return {Object} the `mitt` instance for chaining - * @memberOf mitt - */ - off(type, handler) { - list(type).delete(handler); - return ret; - }, + /** + * Remove an event handler for the given type. + * + * @param {String} type Type of event to unregister `handler` from, or `"*"` + * @param {Function} handler Handler function to remove + * @return {Object} the `mitt` instance for chaining + * @memberOf mitt + */ + off(type, handler) { + list(type).delete(handler); + return ret; + }, - /** - * Invoke all handlers for the given type. - * If present, `"*"` handlers are invoked prior to type-matched handlers. - * - * @param {String} type The event type to invoke - * @param {Any} [arg1] A value (first argument), passed to each handler - * @param {Any} [arg2] A value (second argument), passed to each handler - * @param {Any} [arg3] A value (third argument), passed to each handler - * @return {Object} the `mitt` instance for chaining - * @memberof mitt - */ - emit(type, arg1, arg2, arg3) { - list(type).forEach((handler) => handler(arg1, arg2, arg3)); - list('*').forEach((handler) => handler(type, arg1, arg2, arg3)); - return ret; - } - }; + /** + * Invoke all handlers for the given type. + * If present, `"*"` handlers are invoked prior to type-matched handlers. + * + * @param {String} type The event type to invoke + * @param {Any} [arg1] A value (first argument), passed to each handler + * @param {Any} [arg2] A value (second argument), passed to each handler + * @param {Any} [arg3] A value (third argument), passed to each handler + * @return {Object} the `mitt` instance for chaining + * @memberof mitt + */ + emit(type, arg1, arg2, arg3) { + list(type).forEach((handler) => handler(arg1, arg2, arg3)); + list('*').forEach((handler) => handler(type, arg1, arg2, arg3)); + return ret; + } + }; - // Get or create a named handler list - let list = (type) => { - return ret.all[type = type.toLowerCase()] || (ret.all[type] = new Set()); - }; + // Get or create a named handler list + let list = (type) => { + return ret.all[type = type.toLowerCase()] || (ret.all[type] = new Set()); + }; - return ret; + return ret; } |
