Skip to content

Commit 253337d

Browse files
JiaLiPassionmhevery
authored andcommitted
feat(zone.js): move MutationObserver/FileReader to different module (#31657)
Separate `EventTarget`, `FileReader`, `MutationObserver` and `IntersectionObserver` patches into different module. So the user can disable those modules separately. PR Close #31657
1 parent 6e2db22 commit 253337d

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

packages/zone.js/MODULE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ Below is the full list of currently supported modules.
3636
|requestAnimationFrame|requestAnimationFrame will be patched as Zone MacroTask|__Zone_disable_requestAnimationFrame = true|
3737
|blocking|alert/prompt/confirm will be patched as Zone.run|__Zone_disable_blocking = true|
3838
|EventTarget|target.addEventListener will be patched as Zone aware EventTask|__Zone_disable_EventTarget = true|
39+
|MutationObserver|MutationObserver will be patched as Zone aware operation|__Zone_disable_MutationObserver = true|
40+
|IntersectionObserver|Intersection will be patched as Zone aware operation|__Zone_disable_Intersection = true|
41+
|FileReader|FileReader will be patched as Zone aware operation|__Zone_disable_FileReader = true|
42+
|canvas|HTMLCanvasElement.toBlob will be patched as Zone aware operation|__Zone_disable_canvas = true|
3943
|IE BrowserTools check|in IE, browser tool will not use zone patched eventListener|__Zone_disable_IE_check = true|
4044
|CrossContext check|in webdriver, enable check event listener is cross context|__Zone_enable_cross_context_check = true|
4145
|XHR|XMLHttpRequest will be patched as Zone aware MacroTask|__Zone_disable_XHR = true|

packages/zone.js/lib/browser/browser.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import {findEventTasks} from '../common/events';
1414
import {patchTimer} from '../common/timers';
15-
import {patchClass, patchMethod, patchPrototype, scheduleMacroTaskWithCurrentZone, ZONE_SYMBOL_ADD_EVENT_LISTENER, ZONE_SYMBOL_REMOVE_EVENT_LISTENER, zoneSymbol} from '../common/utils';
15+
import {patchClass, patchMethod, patchPrototype, scheduleMacroTaskWithCurrentZone, ZONE_SYMBOL_ADD_EVENT_LISTENER, ZONE_SYMBOL_REMOVE_EVENT_LISTENER, zoneSymbol,} from '../common/utils';
1616

1717
import {patchCustomElements} from './custom-elements';
1818
import {eventTargetPatch, patchEvent} from './event-target';
@@ -59,9 +59,18 @@ Zone.__load_patch('EventTarget', (global: any, Zone: ZoneType, api: _ZonePrivate
5959
if (XMLHttpRequestEventTarget && XMLHttpRequestEventTarget.prototype) {
6060
api.patchEventTarget(global, [XMLHttpRequestEventTarget.prototype]);
6161
}
62+
});
63+
64+
Zone.__load_patch('MutationObserver', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
6265
patchClass('MutationObserver');
6366
patchClass('WebKitMutationObserver');
67+
});
68+
69+
Zone.__load_patch('IntersectionObserver', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
6470
patchClass('IntersectionObserver');
71+
});
72+
73+
Zone.__load_patch('FileReader', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
6574
patchClass('FileReader');
6675
});
6776

packages/zone.js/lib/zone.configurations.api.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,21 @@ interface ZoneGlobalConfigurations {
325325
*/
326326
__Zone_disable_EventTarget?: boolean;
327327

328+
/**
329+
* Disable the monkey patch of the browser `FileReader` APIs.
330+
*/
331+
__Zone_disable_FileReader?: boolean;
332+
333+
/**
334+
* Disable the monkey patch of the browser `MutationObserver` APIs.
335+
*/
336+
__Zone_disable_MutationObserver?: boolean;
337+
338+
/**
339+
* Disable the monkey patch of the browser `IntersectionObserver` APIs.
340+
*/
341+
__Zone_disable_IntersectionObserver?: boolean;
342+
328343
/**
329344
* Disable the monkey patch of the browser onProperty APIs(such as onclick).
330345
*

0 commit comments

Comments
 (0)