forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Per nodejs#1817, there are many modules that currently abuse the private `_events` property on EventEmitter. One of the ways it is used is to determine if a particular event is being listened for. This adds a simple `listEvents()` method that returns an array of the events with currently registered listeners.
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const EventEmitter = require('events'); | ||
const assert = require('assert'); | ||
|
||
const EE = new EventEmitter(); | ||
const m = () => {}; | ||
EE.on('foo', () => {}); | ||
assert.deepStrictEqual(['foo'], EE.listEvents()); | ||
EE.on('bar', m); | ||
assert.deepStrictEqual(['foo', 'bar'], EE.listEvents()); | ||
EE.removeListener('bar', m); | ||
assert.deepStrictEqual(['foo'], EE.listEvents()); | ||
const s = Symbol('s'); | ||
EE.on(s, m); | ||
assert.deepStrictEqual(['foo', s], EE.listEvents()); | ||
EE.removeListener(s, m); | ||
assert.deepStrictEqual(['foo'], EE.listEvents()); |