mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-06 07:21:16 +08:00
removed prepend and prependonce listener
This commit is contained in:
parent
1e860feca3
commit
a96a0b25bd
@ -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';
|
||||
|
@ -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 = {};
|
||||
|
Loading…
x
Reference in New Issue
Block a user