Skip to content
Myr

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 file

Take it

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 1
1/** Mitt: Tiny (~200b) functional event emitter / pubsub.

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

lines 2–3why, one step back
2 * @name mitt
3 * @returns {Mitt}

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 4
4 */

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

line 5why, one step back
5export default function mitt () {

fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b

line 6why, one step back
6 let all = Object.create(null)

add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c

line 7why, one step back
7 let ret = {

fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b

line 8why, one step back
8 all,

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 9
9

add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c

lines 10–18why, one step back
10 /**
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 back
19 (all[type] || (all[type] = [])).push(handler);

add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c

lines 20–21why, one step back
20 return ret;
21 },

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 22
22

add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c

lines 23–31why, one step back
23 /**
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 back
32 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 back
34 return ret;
35 },

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 36
36

add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c

lines 37–41why, one step back
37 /**
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 invoke

remove "drop support for emitting multiple args" thing as per https://github.com/developit/mitt/pull/19#issuecomment-273344689tunnckoCorebefore adoptionf4c60f4

line 42why, one step back
42 * @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler

add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c

lines 43–45why, one step back
43 * @return {Object} the `mitt` instance for chaining
44 * @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 back
46 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 back
49 return ret;
50 }51 };52 return ret;

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 53
53}