Skip to content
Myr

index.js

This file

Path

src/index.js

48 lines · 1.4 KiB · JavaScript

Last changed by

Remove chaining return values so we don't make #1 impossible (yet?)Jason Millerbefore adoption53a44d8

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 */

Let's keep `all` as an argument for now to avoid a semver breaking changeJason Millerbefore adoption5363bf0

lines 5–6why, one step back
5export default function mitt(all) {
6 all = all || Object.create(null);

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 7
7

Let's keep `all` as an argument for now to avoid a semver breaking changeJason Millerbefore adoption5363bf0

line 8why, one step back
8 return {

add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c

lines 9–17why, one step back
9 /**
10 * Register an event handler for the given type.11 *12 * @param {String} type Type of event to listen for, or `"*"` for all events13 * @param {Function} handler Function to call in response to given event14 * @return {Object} the `mitt` instance for chaining15 * @memberOf mitt16 */17 on(type, handler) {

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

line 18why, one step back
18 (all[type] || (all[type] = [])).push(handler);

add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c

line 19why, one step back
19 },

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 20
20

add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c

lines 21–29why, one step back
21 /**
22 * Remove an event handler for the given type.23 *24 * @param {String} type Type of event to unregister `handler` from, or `"*"`25 * @param {Function} handler Handler function to remove26 * @return {Object} the `mitt` instance for chaining27 * @memberOf mitt28 */29 off(type, handler) {

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

lines 30–31why, one step back
30 let e = all[type] || (all[type] = []);
31 e.splice(e.indexOf(handler) >>> 0, 1);

add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c

line 32why, one step back
32 },

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 33
33

add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c

lines 34–38why, one step back
34 /**
35 * Invoke all handlers for the given type.36 * If present, `"*"` handlers are invoked prior to type-matched handlers.37 *38 * @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 39why, one step back
39 * @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler

add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c

lines 40–42why, one step back
40 * @return {Object} the `mitt` instance for chaining
41 * @memberof mitt42 */

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

lines 43–45why, one step back
43 emit(type, evt) {
44 (all[type] || []).map((handler) => { handler(evt); });45 (all['*'] || []).map((handler) => { handler(type, evt); });

add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c

lines 46–47why, one step back
46 }
47 };

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 48
48}