index.js
This file
Path
src/index.js
53 lines · 1.5 KiB · JavaScript
Last changed by
remove "drop support for emitting multiple args" thing as per https://github.com/developit/mitt/pull/19#issuecomment-273344689tunnckoCorebefore adoptionf4c60f4
History of this fileTake it
1/** Mitt: Tiny (~200b) functional event emitter / pubsub.refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 2–3why, one step back2 * @name mitt3 * @returns {Mitt}4 */refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 5why, one step back5export default function mitt () {fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b
line 6why, one step back6 let all = Object.create(null)add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c
line 7why, one step back7 let ret = {fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b
line 8why, one step back8 all,9add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c
lines 10–18why, one step back10 /**11 * Register an event handler for the given type.12 *13 * @param {String} type Type of event to listen for, or `"*"` for all events14 * @param {Function} handler Function to call in response to given event15 * @return {Object} the `mitt` instance for chaining16 * @memberOf mitt17 */18 on(type, handler) {fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b
line 19why, one step back19 (all[type] || (all[type] = [])).push(handler);add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c
lines 20–21why, one step back20 return ret;21 },22add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c
lines 23–31why, one step back23 /**24 * Remove an event handler for the given type.25 *26 * @param {String} type Type of event to unregister `handler` from, or `"*"`27 * @param {Function} handler Handler function to remove28 * @return {Object} the `mitt` instance for chaining29 * @memberOf mitt30 */31 off(type, handler) {fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b
lines 32–33why, one step back32 let e = all[type] || (all[type] = []);33 e.splice(e.indexOf(handler) >>> 0, 1);add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c
lines 34–35why, one step back34 return ret;35 },36add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c
lines 37–41why, one step back37 /**38 * Invoke all handlers for the given type.39 * If present, `"*"` handlers are invoked prior to type-matched handlers.40 *41 * @param {String} type The event type to invokeremove "drop support for emitting multiple args" thing as per https://github.com/developit/mitt/pull/19#issuecomment-273344689tunnckoCorebefore adoptionf4c60f4
line 42why, one step back42 * @param {Any} [evt] Any value (object is recommended and powerful), passed to each handleradd editorconfig, fix original identationtunnckoCorebefore adoptione7c222c
lines 43–45why, one step back43 * @return {Object} the `mitt` instance for chaining44 * @memberof mitt45 */remove "drop support for emitting multiple args" thing as per https://github.com/developit/mitt/pull/19#issuecomment-273344689tunnckoCorebefore adoptionf4c60f4
lines 46–48why, one step back46 emit(type, evt) {47 (all[type] || []).map((handler) => { handler(evt); });48 (all['*'] || []).map((handler) => { handler(type, evt); });add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c
lines 49–52why, one step back49 return ret;50 }51 };52 return ret;53}