@@ -563,6 +563,48 @@ declare global {
563
563
*/
564
564
__zone_symbol__UNPATCHED_EVENTS ?: string [ ] ;
565
565
566
+ /**
567
+ * Define a list of `on` properties to be ignored when being monkey patched by the `zone.js`.
568
+ *
569
+ * By default, `zone.js` monkey patches `on` properties on inbuilt browser classes as
570
+ * `WebSocket`, `XMLHttpRequest`, `Worker`, `HTMLElement` and others (see `patchTargets` in
571
+ * `propertyDescriptorPatch`). `on` properties may be `WebSocket.prototype.onclose`,
572
+ * `XMLHttpRequest.prototype.onload`, etc.
573
+ *
574
+ * Sometimes, we're not able to customise third-party libraries, which setup `on` listeners.
575
+ * Given a library creates a `Websocket` and sets `socket.onmessage`, this will impact
576
+ * performance if the `onmessage` property is set within the Angular zone, because this will
577
+ * trigger change detection on any message coming through the socket. We can exclude specific
578
+ * targets and their `on` properties from being patched by zone.js.
579
+ *
580
+ * Users can achieve this by defining `__Zone_ignore_on_properties`, it expects an array of
581
+ * objects where `target` is the actual object `on` properties will be set on:
582
+ * ```
583
+ * __Zone_ignore_on_properties = [
584
+ * {
585
+ * target: WebSocket.prototype,
586
+ * ignoreProperties: ['message', 'close', 'open']
587
+ * }
588
+ * ];
589
+ * ```
590
+ *
591
+ * In order to check whether `on` properties have been successfully ignored or not, it's enough
592
+ * to open the console in the browser, run `WebSocket.prototype` and expand the object, we
593
+ * should see the following:
594
+ * ```
595
+ * {
596
+ * __zone_symbol__ononclosepatched: true,
597
+ * __zone_symbol__ononerrorpatched: true,
598
+ * __zone_symbol__ononmessagepatched: true,
599
+ * __zone_symbol__ononopenpatched: true
600
+ * }
601
+ * ```
602
+ * These `__zone_symbol__*` properties are set by zone.js when `on` properties have been patched
603
+ * previously. When `__Zone_ignore_on_properties` is setup, we should not see those properties
604
+ * on targets.
605
+ */
606
+ __Zone_ignore_on_properties ?: { target : any ; ignoreProperties : string [ ] ; } [ ] ;
607
+
566
608
/**
567
609
* Define the event names of the passive listeners.
568
610
*
0 commit comments