removed prepend and prependonce listener

This commit is contained in:
Kai Röder 2018-12-17 18:41:33 +01:00
parent 1e860feca3
commit a96a0b25bd
2 changed files with 0 additions and 40 deletions

View File

@ -157,35 +157,6 @@ describe('Channel', () => {
});
});
describe('method:prependListener', () => {
it('should prepend listener', () => {
const eventName = 'event1';
const prependFn = jest.fn();
channel.addListener(eventName, jest.fn());
channel.prependListener(eventName, prependFn);
expect(channel.listeners(eventName)[0]).toBe(prependFn);
});
});
describe('method:prependOnceListener', () => {
it('should prepend listener and remove it after one execution', () => {
const eventName = 'event1';
const prependFn = jest.fn();
const otherFns = [jest.fn(), jest.fn(), jest.fn()];
otherFns.forEach(fn => channel.addListener(eventName, fn));
channel.prependOnceListener(eventName, prependFn);
channel.emit(eventName);
otherFns.forEach(listener => {
expect(listener).toBe(
channel.listeners(eventName).find(_listener => _listener === listener)
);
});
});
});
describe('method:removeAllListeners', () => {
it('should remove all listeners', () => {
const eventName1 = 'event1';

View File

@ -100,17 +100,6 @@ export class Channel {
this.addListener<TEventArgs>(eventName, onceListener);
}
prependListener<TEventArgs = any>(eventName: string, listener: Listener<TEventArgs>) {
this.events[eventName] = this.events[eventName] || [];
this.events[eventName].unshift(listener);
}
// todo 'listener' is getting mutated by _onceListener, therefore: Input fn() !== Output fn(). This makes testing more difficult
prependOnceListener<TEventArgs = any>(eventName: string, listener: Listener<TEventArgs>) {
const onceListener: Listener = this.onceListener<TEventArgs>(eventName, listener);
this.prependListener(eventName, onceListener);
}
removeAllListeners(eventName?: string) {
if (!eventName) {
this.events = {};