MCPcopy Index your code
hub / github.com/angular/angular / patchEvents

Function patchEvents

packages/zone.js/lib/node/events.ts:12–67  ·  view source on GitHub ↗
(Zone: ZoneType)

Source from the content-addressed store, hash-verified

10import {ZoneType} from '../zone-impl';
11
12export function patchEvents(Zone: ZoneType): void {
13 Zone.__load_patch('EventEmitter', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
14 // For EventEmitter
15 const EE_ADD_LISTENER = 'addListener';
16 const EE_PREPEND_LISTENER = 'prependListener';
17 const EE_REMOVE_LISTENER = 'removeListener';
18 const EE_REMOVE_ALL_LISTENER = 'removeAllListeners';
19 const EE_LISTENERS = 'listeners';
20 const EE_ON = 'on';
21 const EE_OFF = 'off';
22
23 const compareTaskCallbackVsDelegate = function (task: any, delegate: any) {
24 // same callback, same capture, same event name, just return
25 return task.callback === delegate || task.callback.listener === delegate;
26 };
27
28 const eventNameToString = function (eventName: string | Symbol) {
29 if (typeof eventName === 'string') {
30 return eventName;
31 }
32 if (!eventName) {
33 return '';
34 }
35 return eventName.toString().replace('(', '_').replace(')', '_');
36 };
37
38 function patchEventEmitterMethods(obj: any) {
39 const result = patchEventTarget(global, api, [obj], {
40 useG: false,
41 add: EE_ADD_LISTENER,
42 rm: EE_REMOVE_LISTENER,
43 prepend: EE_PREPEND_LISTENER,
44 rmAll: EE_REMOVE_ALL_LISTENER,
45 listeners: EE_LISTENERS,
46 chkDup: false,
47 rt: true,
48 diff: compareTaskCallbackVsDelegate,
49 eventNameToString: eventNameToString,
50 });
51 if (result && result[0]) {
52 obj[EE_ON] = obj[EE_ADD_LISTENER];
53 obj[EE_OFF] = obj[EE_REMOVE_LISTENER];
54 }
55 }
56
57 // EventEmitter
58 let events;
59 try {
60 events = require('events');
61 } catch (err) {}
62
63 if (events && events.EventEmitter) {
64 patchEventEmitterMethods(events.EventEmitter.prototype);
65 }
66 });
67}

Callers 1

patchNodeFunction · 0.90

Calls 2

patchEventEmitterMethodsFunction · 0.85
__load_patchMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…