Example #1
0
 zoneA.run(() => {
   emitter.on('test', shouldNotRun);
   emitter.on('test1', shouldNotRun);
   emitter.removeAllListeners();
   expect(emitter.listeners('test').length).toEqual(0);
   expect(emitter.listeners('test1').length).toEqual(0);
 });
Example #2
0
 zoneA.run(() => {
   const testSymbol = Symbol('test');
   const test1Symbol = Symbol('test1');
   emitter.on(testSymbol, expectZoneA);
   emitter.on(test1Symbol, shouldNotRun);
   emitter.removeListener(test1Symbol, shouldNotRun);
   expect(emitter.listeners(testSymbol).length).toBe(1);
   expect(emitter.listeners(test1Symbol).length).toBe(0);
   emitter.emit(testSymbol, 'test value');
 });
Example #3
0
 zoneA.run(() => {
   emitter.on('removeListener', function(type: string, handler: any) {
     zoneResults.push('remove' + type);
   });
   emitter.on('test', shouldNotRun);
   emitter.on('test1', shouldNotRun);
   emitter.removeAllListeners();
   expect(zoneResults).toEqual(['removetest', 'removetest1']);
   expect(emitter.listeners('test').length).toBe(0);
   expect(emitter.listeners('test1').length).toBe(0);
   expect(emitter.listeners('removeListener').length).toBe(0);
 });
Example #4
0
    zoneA.run(() => {
      emitter.on('test', listenerA);
      emitter.on('test', listenerB);
      expect(emitter.listeners('test')).toEqual([listenerA, listenerB]);
      emitter.emit('test');
      expect(zoneResults).toEqual(['A', 'B']);
      zoneResults = [];

      emitter.removeAllListeners('test');

      emitter.on('test', listenerA);
      emitter.prependListener('test', listenerB);
      expect(emitter.listeners('test')).toEqual([listenerB, listenerA]);
      emitter.emit('test');
      expect(zoneResults).toEqual(['B', 'A']);
    });
    emit(event: string, ...args: Array<any>): Bluebird<Array<void>> {
        const promises: Array<Bluebird<void>> = [];

        this.events.listeners(event).forEach(listener => {
            promises.push(listener(...args));
        });

        return Bluebird.all(promises);
    }
Example #6
0
 it('should return all listeners for an event', () => {
   zoneA.run(() => {
     emitter.on('test', expectZoneA);
   });
   zoneB.run(() => {
     emitter.on('test', shouldNotRun);
   });
   expect(emitter.listeners('test')).toEqual([expectZoneA, shouldNotRun]);
 });
Example #7
0
emitter.addListener('send', listener1);

emitter.on('send', listener2);

emitter.on('send', listener3);

emitter.once('send', listener);

emitter.once(1, listener4);

emitter.prependListener('send', listener5);

emitter.prependOnceListener('send', listener6);

emitter.listeners('send');
emitter.listenerCount('send');
emitter.rawListeners('send');

EventEmitter.defaultMaxListeners = 100;
console.log(`count(static): ${EventEmitter.listenerCount(emitter, 'send')}`);
console.log(`ncount: ${emitter.listenerCount('send')}`);
console.log(`maxListeners: ${emitter.getMaxListeners()}`);
console.log(`eventNames: ${emitter.eventNames().join(', ')}`);
console.log(`rawListeners count: ${emitter.rawListeners('send').length}`);

setTimeout(() => {
  console.log('\n');
  emitter.emit('send');
}, 1000);
Example #8
0
{
    let result: number;

    result = events.EventEmitter.defaultMaxListeners;
    result = events.EventEmitter.listenerCount(emitter, event); // deprecated

    const promise: Promise<any> = events.once(new events.EventEmitter(), 'error');

    result = emitter.getMaxListeners();
    result = emitter.listenerCount(event);
}

{
    let result: Function[];

    result = emitter.listeners(event);
}

{
    let result: boolean;

    result = emitter.emit(event);
    result = emitter.emit(event, any);
    result = emitter.emit(event, any, any);
    result = emitter.emit(event, any, any, any);
}

{
    let result: Array<string | symbol>;

    result = emitter.eventNames();
Example #9
0
 zoneA.run(() => {
   expect(emitter.listeners('test')).toEqual([]);
 });
Example #10
0
 zoneA.run(() => {
   emitter.once('test', expectZoneA);
   emitter.emit('test', 'test value');
   expect(emitter.listeners('test').length).toEqual(0);
 });
Example #11
0
 zoneA.run(() => {
   emitter.on('test', expectZoneA);
   emitter.on('test', expectZoneA);
   expect(emitter.removeAllListeners('test')).toEqual(emitter);
   expect(emitter.listeners('test').length).toEqual(0);
 });