const removeSocketListener = (
    subscriptionUrl: string, 
    subscriptionId: string, 
    callback: Subscriptions.HookCallback<any, any> | Subscriptions.SubscriptionCallback<any>, 
    sendApi: boolean
  ) => {
    if (!socket().isConnected()) {
      return;
    }

    subscriptions[subscriptionId]--;
    emitter.removeListener(subscriptionId, callback);

    if (subscriptions[subscriptionId] === 0) {
      if (sendApi && socket().isConnected()) {
        socket().delete(subscriptionUrl)
          .catch(
            (error: Requests.ErrorResponse) => {
              logger.error('Failed to remove socket listener', subscriptionUrl, error);
            });
      }

      delete subscriptions[subscriptionId];
    }
  };
    this.hasProp<Camera>("camera", (instance, newValue) => {
      const cameraHelperUserData = instance.userData as any;

      const cameraEventListener = cameraHelperUserData[cameraEventListenerSymbol];

      if (instance.camera !== defaultCamera) {
        const userData = instance.camera.userData as any;

        const cameraEventEmitter: EventEmitter = userData[cameraEventsSymbol];

        cameraEventEmitter
          .removeListener(cameraEventProjectionMatrixUpdated, cameraEventListener);
      }

      let cameraToUse = newValue;

      if (cameraToUse == null) {
        cameraToUse = defaultCamera;
      } else {
        const userData = newValue.userData as any;

        userData[cameraEventsSymbol]
          .addListener(cameraEventProjectionMatrixUpdated, cameraEventListener);
      }

      instance.camera = cameraToUse;

      instance.matrix = cameraToUse.matrixWorld;

      instance.update();
    }, false);
Example #3
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 #4
0
 zoneA.run(() => {
   emitter.on('removeListener', function(type: string, handler: any) {
     zoneResults.push('remove' + type);
   });
   emitter.on('newListener', function(type: string, handler: any) {
     zoneResults.push('new' + type);
   });
   emitter.on('test', shouldNotRun);
   emitter.removeListener('test', shouldNotRun);
   expect(zoneResults).toEqual(['newtest', 'removetest']);
 });
Example #5
0
 function fail() : void {
   obj.removeListener(event, handler);
   cb("timeout");
 }
Example #6
0
 var off = () => {
     this.emitter.removeListener('change', handler);
 };
 const removeLocalListener = (
   subscriptionId: string, 
   callback: Subscriptions.HookCallback<any, any> | Subscriptions.SubscriptionCallback<any>
 ) => {
   emitter.removeListener(subscriptionId, callback);
 };
Example #8
0
import * as events from 'events';

const emitter: events.EventEmitter = new events.EventEmitter();
const event: string | symbol = '';
const listener: (...args: any[]) => void = () => {};
const any: any = 1;

{
    let result: events.EventEmitter;

    result = emitter.addListener(event, listener);
    result = emitter.on(event, listener);
    result = emitter.once(event, listener);
    result = emitter.prependListener(event, listener);
    result = emitter.prependOnceListener(event, listener);
    result = emitter.removeListener(event, listener);
    result = emitter.off(event, listener);
    result = emitter.removeAllListeners();
    result = emitter.removeAllListeners(event);
    result = emitter.setMaxListeners(42);
}

{
    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();
Example #9
0
 zoneA.run(() => {
   emitter.on('test', shouldNotRun);
   expect(emitter.removeListener('test', shouldNotRun)).toEqual(emitter);
   emitter.emit('test', 'test value');
 });
Example #10
0
 off(eventName: string, callback: any) {
   this.events.removeListener(eventName, callback)
 }
Example #11
0
 zoneA.run(() => {
   emitter.on('test', shouldNotRun);
   emitter.on('test2', shouldNotRun);
   emitter.removeListener('test', shouldNotRun);
 });
 .add("EventEmitter", () => {
     function listener() { }
     const event = events[seq++ % events.length];
     eventEmitter.on(event, listener);
     eventEmitter.removeListener(event, listener);
 })
Example #13
0
	removeListener(handler: (message: any) => void): void {
		this.emitter.removeListener('message', handler);
	}
Example #14
0
 removeChangeListener(callback) {
   this._emitter.removeListener(CHANGE_EVENT, callback);
 }
Example #15
0
 h => e.removeListener(EVENT_TYPE, h)
Example #16
0
 .once("removeAllListeners", (): void => {
   this.parentEmitter.removeListener(eventName, handler);
 });
Example #17
0
 .once(`unsubscribe:${subscription}`, (): void => {
   this.removeListener(eventName, publish);
   this.parentEmitter.removeListener(eventName, handler);
 })
Example #18
0
setTimeout(() => {
  console.log('\n');
  emitter.emit('send');
  emitter.removeListener('send', listener2);
}, 2000);
Example #19
0
 zoneB.run(() => {
   emitter.removeListener('test2', shouldNotRun);
   emitter.emit('test', 'test value');
   emitter.emit('test2', 'test value');
 });
Example #20
0
	const onLastListenerRemove = () => emitter.removeListener(eventName, fn);
Example #21
0
 removeChangeListener(callback: () => void) {
   this.emitter.removeListener(CHANGE_EVENT, callback);
 }