MCPcopy Create free account
hub / github.com/angular/angular / invokeTask

Function invokeTask

packages/zone.js/lib/common/events.ts:221–252  ·  view source on GitHub ↗
(task: any, target: any, event: Event)

Source from the content-addressed store, hash-verified

219 const PREPEND_EVENT_LISTENER_SOURCE = '.' + PREPEND_EVENT_LISTENER + ':';
220
221 const invokeTask = function (task: any, target: any, event: Event): Error | undefined {
222 // for better performance, check isRemoved which is set
223 // by removeEventListener
224 if (task.isRemoved) {
225 return;
226 }
227 const delegate = task.callback;
228 if (typeof delegate === 'object' && delegate.handleEvent) {
229 // create the bind version of handleEvent when invoke
230 task.callback = (event: Event) => delegate.handleEvent(event);
231 task.originalDelegate = delegate;
232 }
233 // invoke static task.invoke
234 // need to try/catch error here, otherwise, the error in one event listener
235 // will break the executions of the other event listeners. Also error will
236 // not remove the event listener when `once` options is true.
237 let error;
238 try {
239 task.invoke(task, target, [event]);
240 } catch (err: any) {
241 error = err;
242 }
243 const options = task.options;
244 if (options && typeof options === 'object' && options.once) {
245 // if options.once is true, after invoke once remove listener here
246 // only browser need to do this, nodejs eventEmitter will cal removeListener
247 // inside EventEmitter.once
248 const delegate = task.originalDelegate ? task.originalDelegate : task.callback;
249 target[REMOVE_EVENT_LISTENER].call(target, event.type, delegate, options);
250 }
251 return error;
252 };
253
254 function globalCallback(context: unknown, event: Event, isCapture: boolean) {
255 // https://github.com/angular/zone.js/issues/911, in IE, sometimes

Callers 1

globalCallbackFunction · 0.85

Calls 2

handleEventMethod · 0.80
invokeMethod · 0.65

Tested by

no test coverage detected