Skip to content

Commit 6ed861d

Browse files
Raynosisaacs
authored andcommitted
events: have events module exports EventEmitter
This change is 100% backwards compatible. This change will make using `EventEmitter` slightly simpler / nicer and adheres to the best practice set forth by substack. ```js var EventEmitter = require("events") var emitter = new EventEmitter() ``` The only difference is that we now have to set `EventEmitter` as a property of `EventEmitter` for backwards compatibility like we do with [`Stream`][1] We have also set the `usingDomains` property on the `EventEmitter` constructor itself because that aligns with it's current usage of `require("events").usingDomains = true` There are other internals that would benefit from this change as well like `StringDecoder`
1 parent c171c49 commit 6ed861d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/events.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222
var domain;
2323
var util = require('util');
2424

25-
exports.usingDomains = false;
26-
2725
function EventEmitter() {
2826
this.domain = null;
29-
if (exports.usingDomains) {
27+
if (EventEmitter.usingDomains) {
3028
// if there is an active domain, then attach to it.
3129
domain = domain || require('domain');
3230
if (domain.active && !(this instanceof domain.Domain)) {
@@ -36,7 +34,12 @@ function EventEmitter() {
3634
this._events = this._events || {};
3735
this._maxListeners = this._maxListeners || undefined;
3836
}
39-
exports.EventEmitter = EventEmitter;
37+
module.exports = EventEmitter;
38+
39+
// Backwards-compat with node 0.10.x
40+
EventEmitter.EventEmitter = EventEmitter;
41+
42+
EventEmitter.usingDomains = false;
4043

4144
EventEmitter.prototype.domain = undefined;
4245
EventEmitter.prototype._events = undefined;

0 commit comments

Comments
 (0)