Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit ab72df6

Browse files
JiaLiPassionmhevery
authored andcommittedMar 14, 2018
fix(event): fix #1021, removeListener/removeAllListeners should return eventEmitter (#1022)
1 parent eefe983 commit ab72df6

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
 

‎lib/common/events.ts

+7
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,9 @@ export function patchEventTarget(
497497
target[symbolEventName] = null;
498498
}
499499
existingTask.zone.cancelTask(existingTask);
500+
if (returnTarget) {
501+
return target;
502+
}
500503
return;
501504
}
502505
}
@@ -571,6 +574,10 @@ export function patchEventTarget(
571574
}
572575
}
573576
}
577+
578+
if (returnTarget) {
579+
return this;
580+
}
574581
};
575582

576583
// for native toString patch

‎test/node/events.spec.ts

+15
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ describe('nodejs EventEmitter', () => {
6666
emitter.emit('test2', 'test value');
6767
});
6868
});
69+
it('remove listener should return event emitter', () => {
70+
zoneA.run(() => {
71+
emitter.on('test', shouldNotRun);
72+
expect(emitter.removeListener('test', shouldNotRun)).toEqual(emitter);
73+
emitter.emit('test', 'test value');
74+
});
75+
});
6976
it('should return all listeners for an event', () => {
7077
zoneA.run(() => {
7178
emitter.on('test', expectZoneA);
@@ -106,6 +113,14 @@ describe('nodejs EventEmitter', () => {
106113
expect(emitter.listeners('test').length).toEqual(0);
107114
});
108115
});
116+
it('remove All listeners should return event emitter', () => {
117+
zoneA.run(() => {
118+
emitter.on('test', expectZoneA);
119+
emitter.on('test', expectZoneA);
120+
expect(emitter.removeAllListeners('test')).toEqual(emitter);
121+
expect(emitter.listeners('test').length).toEqual(0);
122+
});
123+
});
109124
it('should remove All listeners properly even without a type parameter', () => {
110125
zoneA.run(() => {
111126
emitter.on('test', shouldNotRun);

0 commit comments

Comments
 (0)
This repository has been archived.