Skip to content

Commit

Permalink
refactor: rename unpatched event flag in Zone from `BLACK_LISTED_EVEN…
Browse files Browse the repository at this point in the history
…TS` to `UNPATCHED_EVENTS` (angular#29617)

Closes angular#28529

PR Close angular#29617
  • Loading branch information
JiaLiPassion authored and atscott committed Oct 4, 2019
1 parent 442f323 commit 53d13c3
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion aio/content/guide/browser-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ For example:
*/
// __Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
// __Zone_disable_on_property = true; // disable patch onProperty such as onclick
// __zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
// __zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames

/*
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
Expand Down
6 changes: 4 additions & 2 deletions aio/tools/examples/shared/boilerplate/cli/src/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@
*
* The following flags will work for all browsers.
*
* (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
* (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch
* requestAnimationFrame
* (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
* (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
* (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch
* specified eventNames
*
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
* with the following flag, it will bypass `zone.js` patch for IE/Edge
Expand Down
2 changes: 1 addition & 1 deletion integration/cli-hello-world-ivy-compat/src/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
*
* (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
* (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
* (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
* (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
*
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
* with the following flag, it will bypass `zone.js` patch for IE/Edge
Expand Down
2 changes: 1 addition & 1 deletion integration/cli-hello-world-ivy-minimal/src/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
*
* (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
* (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
* (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
* (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
*
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
* with the following flag, it will bypass `zone.js` patch for IE/Edge
Expand Down
2 changes: 1 addition & 1 deletion integration/cli-hello-world/src/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
*
* (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
* (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
* (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
* (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
*
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
* with the following flag, it will bypass `zone.js` patch for IE/Edge
Expand Down
26 changes: 12 additions & 14 deletions packages/platform-browser/src/dom/events/dom_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,22 @@ const NATIVE_REMOVE_LISTENER = 'removeEventListener';
const stopSymbol = '__zone_symbol__propagationStopped';
const stopMethodSymbol = '__zone_symbol__stopImmediatePropagation';


const blackListedMap = (() => {
const blackListedEvents: string[] =
(typeof Zone !== 'undefined') && (Zone as any)[__symbol__('BLACK_LISTED_EVENTS')];
if (blackListedEvents) {
const res: {[eventName: string]: string} = {};
blackListedEvents.forEach(eventName => { res[eventName] = eventName; });
return res;
const unpatchedMap: {[key: string]: string}|undefined = (() => {
const unpatchedEvents =
(typeof Zone !== 'undefined') && (Zone as any)[__symbol__('UNPATCHED_EVENTS')];
if (unpatchedEvents) {
const unpatchedEventMap: {[eventName: string]: string} = {};
unpatchedEvents.forEach((eventName: string) => { unpatchedEventMap[eventName] = eventName; });
return unpatchedEventMap;
}
return undefined;
})();


const isBlackListedEvent = function(eventName: string) {
if (!blackListedMap) {
const isUnpatchedEvent = function(eventName: string) {
if (!unpatchedMap) {
return false;
}
return blackListedMap.hasOwnProperty(eventName);
return unpatchedMap.hasOwnProperty(eventName);
};

interface TaskData {
Expand Down Expand Up @@ -160,7 +158,7 @@ export class DomEventsPlugin extends EventManagerPlugin {
let callback: EventListener = handler as EventListener;
// if zonejs is loaded and current zone is not ngZone
// we keep Zone.current on target for later restoration.
if (zoneJsLoaded && (!NgZone.isInAngularZone() || isBlackListedEvent(eventName))) {
if (zoneJsLoaded && (!NgZone.isInAngularZone() || isUnpatchedEvent(eventName))) {
let symbolName = symbolNames[eventName];
if (!symbolName) {
symbolName = symbolNames[eventName] = __symbol__(ANGULAR + eventName + FALSE);
Expand All @@ -171,7 +169,7 @@ export class DomEventsPlugin extends EventManagerPlugin {
taskDatas = (element as any)[symbolName] = [];
}

const zone = isBlackListedEvent(eventName) ? Zone.root : Zone.current;
const zone = isUnpatchedEvent(eventName) ? Zone.root : Zone.current;
if (taskDatas.length === 0) {
taskDatas.push({zone: zone, handler: callback});
} else {
Expand Down
2 changes: 1 addition & 1 deletion test-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
* found in the LICENSE file at https://angular.io/license
*/

Zone[Zone.__symbol__('BLACK_LISTED_EVENTS')] = ['scroll'];
Zone[Zone.__symbol__('UNPATCHED_EVENTS')] = ['scroll'];

0 comments on commit 53d13c3

Please sign in to comment.