a zip code crypto-currency system good for red ONLY

events.ts 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * @license
  3. * Copyright Google Inc. All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. import {patchEventTarget} from '../common/events';
  9. Zone.__load_patch('EventEmitter', (global: any) => {
  10. // For EventEmitter
  11. const EE_ADD_LISTENER = 'addListener';
  12. const EE_PREPEND_LISTENER = 'prependListener';
  13. const EE_REMOVE_LISTENER = 'removeListener';
  14. const EE_REMOVE_ALL_LISTENER = 'removeAllListeners';
  15. const EE_LISTENERS = 'listeners';
  16. const EE_ON = 'on';
  17. const compareTaskCallbackVsDelegate = function(task: any, delegate: any) {
  18. // same callback, same capture, same event name, just return
  19. return task.callback === delegate || task.callback.listener === delegate;
  20. };
  21. function patchEventEmitterMethods(obj: any) {
  22. const result = patchEventTarget(global, [obj], {
  23. useG: false,
  24. add: EE_ADD_LISTENER,
  25. rm: EE_REMOVE_LISTENER,
  26. prepend: EE_PREPEND_LISTENER,
  27. rmAll: EE_REMOVE_ALL_LISTENER,
  28. listeners: EE_LISTENERS,
  29. chkDup: false,
  30. rt: true,
  31. diff: compareTaskCallbackVsDelegate
  32. });
  33. if (result && result[0]) {
  34. obj[EE_ON] = obj[EE_ADD_LISTENER];
  35. }
  36. }
  37. // EventEmitter
  38. let events;
  39. try {
  40. events = require('events');
  41. } catch (err) {
  42. }
  43. if (events && events.EventEmitter) {
  44. patchEventEmitterMethods(events.EventEmitter.prototype);
  45. }
  46. });