Skip to content

Commit 0f41ead

Browse files
committed
Merge branch 'expose-all' of https://github.com/jaylinski/mitt
2 parents 5116df4 + 76a353c commit 0f41ead

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ emitter.on('*', (type, e) => console.log(type, e) )
6969
// fire an event
7070
emitter.emit('foo', { a: 'b' })
7171

72+
// clearing all events
73+
emitter.all.clear()
74+
7275
// working with handler references:
7376
function onFoo() {}
7477
emitter.on('foo', onFoo) // listen
@@ -99,6 +102,7 @@ const emitter: mitt.Emitter = mitt();
99102
#### Table of Contents
100103

101104
- [mitt](#mitt)
105+
- [all](#all)
102106
- [on](#on)
103107
- [Parameters](#parameters)
104108
- [off](#off)
@@ -112,6 +116,10 @@ Mitt: Tiny (~200b) functional event emitter / pubsub.
112116

113117
Returns **Mitt**
114118

119+
### all
120+
121+
A Map of event names to registered handler functions.
122+
115123
### on
116124

117125
Register an event handler for the given type.

src/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export type WildCardEventHandlerList = Array<WildcardHandler>;
1313
export type EventHandlerMap = Map<EventType, EventHandlerList | WildCardEventHandlerList>;
1414

1515
export interface Emitter {
16+
all: EventHandlerMap;
17+
1618
on<T = any>(type: EventType, handler: Handler<T>): void;
1719
on(type: '*', handler: WildcardHandler): void;
1820

@@ -23,15 +25,21 @@ export interface Emitter {
2325
emit(type: '*', event?: any): void;
2426
}
2527

26-
/** Mitt: Tiny (~200b) functional event emitter / pubsub.
27-
* @name mitt
28-
* @returns {Mitt}
28+
/**
29+
* Mitt: Tiny (~200b) functional event emitter / pubsub.
30+
* @name mitt
31+
* @returns {Mitt}
2932
*/
3033
export default function mitt(all?: EventHandlerMap): Emitter {
3134
all = all || new Map();
3235

3336
return {
3437

38+
/**
39+
* A Map of event names to registered handler functions.
40+
*/
41+
all,
42+
3543
/**
3644
* Register an event handler for the given type.
3745
* @param {string|symbol} type Type of event to listen for, or `"*"` for all events
@@ -48,7 +56,6 @@ export default function mitt(all?: EventHandlerMap): Emitter {
4856

4957
/**
5058
* Remove an event handler for the given type.
51-
*
5259
* @param {string|symbol} type Type of event to unregister `handler` from, or `"*"`
5360
* @param {Function} handler Handler function to remove
5461
* @memberOf mitt

test/index_test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ describe('mitt#', () => {
3030
inst = mitt(events);
3131
});
3232

33+
describe('properties', () => {
34+
it('should expose the event handler map', () => {
35+
expect(inst)
36+
.to.have.property('all')
37+
.that.is.a('map');
38+
});
39+
});
40+
3341
describe('on()', () => {
3442
it('should be a function', () => {
3543
expect(inst)

0 commit comments

Comments
 (0)