mirror of https://github.com/lukechilds/node.git
Browse Source
Per https://github.com/nodejs/node/issues/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 `eventNames()` method that returns an array of the events with currently registered listeners. PR-URL: https://github.com/nodejs/node/pull/5617 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>process-exit-stdio-flushing
James M Snell
9 years ago
3 changed files with 46 additions and 0 deletions
@ -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.eventNames()); |
||||
|
EE.on('bar', m); |
||||
|
assert.deepStrictEqual(['foo', 'bar'], EE.eventNames()); |
||||
|
EE.removeListener('bar', m); |
||||
|
assert.deepStrictEqual(['foo'], EE.eventNames()); |
||||
|
const s = Symbol('s'); |
||||
|
EE.on(s, m); |
||||
|
assert.deepStrictEqual(['foo', s], EE.eventNames()); |
||||
|
EE.removeListener(s, m); |
||||
|
assert.deepStrictEqual(['foo'], EE.eventNames()); |
Loading…
Reference in new issue