refactor(zone.js): remove usages of blacklist related to UNPATCHED_EVENTS (#38930)
Remove usages of blacklist around UNPATCHED_EVENTS configuration PR Close #38930
This commit is contained in:
parent
ba3f4c26bb
commit
75610505c6
|
@ -127,10 +127,10 @@ ZoneAwareError makes sure that `this` is ZoneAwareError even without new.
|
||||||
ZoneAwarePromise wraps the global Promise and makes it run in zones as a MicroTask.
|
ZoneAwarePromise wraps the global Promise and makes it run in zones as a MicroTask.
|
||||||
It also passes promise A+ tests.
|
It also passes promise A+ tests.
|
||||||
|
|
||||||
## BlackListEvents
|
## UnpatchedEvents
|
||||||
|
|
||||||
Sometimes we don't want some `event` to be patched by `zone.js`, we can blacklist events
|
Sometimes we don't want some `event` to be patched by `zone.js`, we can instruct zone.js to leave
|
||||||
by following settings.
|
these `event` to be unpatched by following settings.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// disable on properties
|
// disable on properties
|
||||||
|
@ -144,5 +144,5 @@ by following settings.
|
||||||
});
|
});
|
||||||
|
|
||||||
// disable addEventListener
|
// disable addEventListener
|
||||||
global['__zone_symbol__BLACK_LISTED_EVENTS'] = ['scroll'];
|
global['__zone_symbol__UNPATCHED_EVENTS'] = ['scroll'];
|
||||||
```
|
```
|
||||||
|
|
|
@ -351,7 +351,7 @@ export function patchEventTarget(
|
||||||
const compare =
|
const compare =
|
||||||
(patchOptions && patchOptions.diff) ? patchOptions.diff : compareTaskCallbackVsDelegate;
|
(patchOptions && patchOptions.diff) ? patchOptions.diff : compareTaskCallbackVsDelegate;
|
||||||
|
|
||||||
const blackListedEvents: string[] = (Zone as any)[zoneSymbol('BLACK_LISTED_EVENTS')];
|
const unpatchedEvents: string[] = (Zone as any)[zoneSymbol('UNPATCHED_EVENTS')];
|
||||||
const passiveEvents: string[] = _global[zoneSymbol('PASSIVE_EVENTS')];
|
const passiveEvents: string[] = _global[zoneSymbol('PASSIVE_EVENTS')];
|
||||||
|
|
||||||
const makeAddListener = function(
|
const makeAddListener = function(
|
||||||
|
@ -391,10 +391,10 @@ export function patchEventTarget(
|
||||||
passiveSupported && !!passiveEvents && passiveEvents.indexOf(eventName) !== -1;
|
passiveSupported && !!passiveEvents && passiveEvents.indexOf(eventName) !== -1;
|
||||||
const options = buildEventListenerOptions(arguments[2], passive);
|
const options = buildEventListenerOptions(arguments[2], passive);
|
||||||
|
|
||||||
if (blackListedEvents) {
|
if (unpatchedEvents) {
|
||||||
// check black list
|
// check upatched list
|
||||||
for (let i = 0; i < blackListedEvents.length; i++) {
|
for (let i = 0; i < unpatchedEvents.length; i++) {
|
||||||
if (eventName === blackListedEvents[i]) {
|
if (eventName === unpatchedEvents[i]) {
|
||||||
if (passive) {
|
if (passive) {
|
||||||
return nativeListener.call(target, eventName, delegate, options);
|
return nativeListener.call(target, eventName, delegate, options);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1154,10 +1154,10 @@ describe('Zone', function() {
|
||||||
it('should not be passive with global variable defined with passive false option', () => {
|
it('should not be passive with global variable defined with passive false option', () => {
|
||||||
testPassive('touchstart', 'defaultPrevented', {passive: false});
|
testPassive('touchstart', 'defaultPrevented', {passive: false});
|
||||||
});
|
});
|
||||||
it('should be passive with global variable defined and also blacklisted', () => {
|
it('should be passive with global variable defined and also unpatched', () => {
|
||||||
testPassive('scroll', 'default will run', undefined);
|
testPassive('scroll', 'default will run', undefined);
|
||||||
});
|
});
|
||||||
it('should not be passive without global variable defined and also blacklisted', () => {
|
it('should not be passive without global variable defined and also unpatched', () => {
|
||||||
testPassive('wheel', 'defaultPrevented', undefined);
|
testPassive('wheel', 'defaultPrevented', undefined);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1376,7 +1376,7 @@ describe('Zone', function() {
|
||||||
let hookSpy2 = jasmine.createSpy('spy2');
|
let hookSpy2 = jasmine.createSpy('spy2');
|
||||||
let hookSpy3 = jasmine.createSpy('spy3');
|
let hookSpy3 = jasmine.createSpy('spy3');
|
||||||
let logs: string[] = [];
|
let logs: string[] = [];
|
||||||
const isBlacklistedEvent = function(source: string) {
|
const isUnpatchedEvent = function(source: string) {
|
||||||
return source.lastIndexOf('click') !== -1;
|
return source.lastIndexOf('click') !== -1;
|
||||||
};
|
};
|
||||||
const zone1 = Zone.current.fork({
|
const zone1 = Zone.current.fork({
|
||||||
|
@ -1385,7 +1385,7 @@ describe('Zone', function() {
|
||||||
parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task):
|
parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task):
|
||||||
any => {
|
any => {
|
||||||
if ((task.type === 'eventTask' || task.type === 'macroTask') &&
|
if ((task.type === 'eventTask' || task.type === 'macroTask') &&
|
||||||
isBlacklistedEvent(task.source)) {
|
isUnpatchedEvent(task.source)) {
|
||||||
task.cancelScheduleRequest();
|
task.cancelScheduleRequest();
|
||||||
|
|
||||||
return zone2.scheduleTask(task);
|
return zone2.scheduleTask(task);
|
||||||
|
|
Loading…
Reference in New Issue