Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 3805443

Browse files
committed
fix(webapi): refactor webapi to not import util.ts directly
1 parent 14c7a6f commit 3805443

9 files changed

+52
-12
lines changed

Diff for: dist/webapis-media-query.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/webapis-notification.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: gulpfile.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,19 @@ gulp.task('build/zone.min.js', ['compile-esm'], function(cb) {
9292
});
9393

9494
gulp.task('build/webapis-media-query.js', ['compile-esm'], function(cb) {
95-
return generateScript('./lib/browser/webapis-media-query.ts', 'webapis-media-query.js', true, cb);
95+
return generateScript('./lib/browser/webapis-media-query.ts', 'webapis-media-query.js', false, cb);
96+
});
97+
98+
gulp.task('build/webapis-media-query.min.js', ['compile-esm'], function(cb) {
99+
return generateScript('./lib/browser/webapis-media-query.ts', 'webapis-media-query.min.js', true, cb);
96100
});
97101

98102
gulp.task('build/webapis-notification.js', ['compile-esm'], function(cb) {
99-
return generateScript('./lib/browser/webapis-notification.ts', 'webapis-notification.js', true, cb);
103+
return generateScript('./lib/browser/webapis-notification.ts', 'webapis-notification.js', false, cb);
104+
});
105+
106+
gulp.task('build/webapis-notification.min.js', ['compile-esm'], function(cb) {
107+
return generateScript('./lib/browser/webapis-notification.ts', 'webapis-notification.min.js', true, cb);
100108
});
101109

102110
gulp.task('build/jasmine-patch.js', ['compile-esm'], function(cb) {
@@ -165,7 +173,9 @@ gulp.task('build', [
165173
'build/zone.min.js',
166174
'build/zone-node.js',
167175
'build/webapis-media-query.js',
176+
'build/webapis-media-query.min.js',
168177
'build/webapis-notification.js',
178+
'build/webapis-notification.min.js',
169179
'build/zone-mix.js',
170180
'build/jasmine-patch.js',
171181
'build/jasmine-patch.min.js',

Diff for: lib/browser/webapis-media-query.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import {NestedEventListenerOrEventListenerObject, patchEventTargetMethods} from '../common/utils';
9-
108
((_global: any) => {
119
// patch MediaQuery
1210
patchMediaQuery(_global);
@@ -15,6 +13,7 @@ import {NestedEventListenerOrEventListenerObject, patchEventTargetMethods} from
1513
if (!_global['MediaQueryList']) {
1614
return;
1715
}
16+
const patchEventTargetMethods = Zone[Zone['__symbol__']('patchEventTargetMethods')];
1817
patchEventTargetMethods(
1918
_global['MediaQueryList'].prototype, 'addListener', 'removeListener', (self, args) => {
2019
return {
@@ -23,16 +22,14 @@ import {NestedEventListenerOrEventListenerObject, patchEventTargetMethods} from
2322
handler: args[0],
2423
target: self || _global,
2524
name: 'mediaQuery',
26-
invokeAddFunc: function(
27-
addFnSymbol: any, delegate: Task|NestedEventListenerOrEventListenerObject) {
25+
invokeAddFunc: function(addFnSymbol: any, delegate) {
2826
if (delegate && (<Task>delegate).invoke) {
2927
return this.target[addFnSymbol]((<Task>delegate).invoke);
3028
} else {
3129
return this.target[addFnSymbol](delegate);
3230
}
3331
},
34-
invokeRemoveFunc: function(
35-
removeFnSymbol: any, delegate: Task|NestedEventListenerOrEventListenerObject) {
32+
invokeRemoveFunc: function(removeFnSymbol: any, delegate) {
3633
if (delegate && (<Task>delegate).invoke) {
3734
return this.target[removeFnSymbol]((<Task>delegate).invoke);
3835
} else {

Diff for: lib/browser/webapis-notification.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import {patchOnProperties} from '../common/utils';
9-
108
((_global: any) => {
119
// patch Notification
1210
patchNotification(_global);
@@ -16,7 +14,7 @@ import {patchOnProperties} from '../common/utils';
1614
if (!Notification || !Notification.prototype) {
1715
return;
1816
}
19-
17+
const patchOnProperties = Zone[Zone['__symbol__']('patchOnProperties')];
2018
patchOnProperties(Notification.prototype, null);
2119
}
2220
})(typeof window === 'object' && window || typeof self === 'object' && self || global);

Diff for: lib/common/utils.ts

+11
Original file line numberDiff line numberDiff line change
@@ -569,3 +569,14 @@ export function findEventTask(target: any, evtName: string): Task[] {
569569
}
570570
return result;
571571
}
572+
573+
Zone[zoneSymbol('patchEventTargetMethods')] = patchEventTargetMethods;
574+
Zone[zoneSymbol('patchMicroTask')] = patchMicroTask;
575+
Zone[zoneSymbol('patchMacroTask')] = patchMacroTask;
576+
Zone[zoneSymbol('patchClass')] = patchClass;
577+
Zone[zoneSymbol('patchProperty')] = patchProperty;
578+
Zone[zoneSymbol('patchOnProperties')] = patchOnProperties;
579+
Zone[zoneSymbol('isNode')] = isNode;
580+
Zone[zoneSymbol('isBrowser')] = isBrowser;
581+
Zone[zoneSymbol('isMix')] = isMix;
582+
Zone[zoneSymbol('isWebWorker')] = isWebWorker;

Diff for: test/browser/MediaQuery.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('test mediaQuery patch', ifEnvSupports(supportMediaQuery, () => {
2121
it('test whether addListener is patched', () => {
2222
const mqList = window.matchMedia('min-width:500px');
2323
if (mqList && mqList['addListener']) {
24-
expect(mqList[zoneSymbol('addListener')]).not.toBe(undefined);
24+
expect(mqList[zoneSymbol('addListener')]).toBeTruthy();
2525
}
2626
});
2727
}));

Diff for: test/browser/Notification.spec.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import '../../lib/browser/webapis-notification';
10+
11+
import {zoneSymbol} from '../../lib/common/utils';
12+
import {ifEnvSupports} from '../test-util';
13+
14+
describe('Notification API', ifEnvSupports('Notification', function() {
15+
it('Notification API should be patched by Zone', () => {
16+
const _global =
17+
typeof window === 'object' && window || typeof self === 'object' && self || global;
18+
const Notification = _global['Notification'];
19+
expect(Notification.prototype[zoneSymbol('addEventListener')]).toBeTruthy();
20+
});
21+
}));

Diff for: test/browser_entry_point.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ import './browser/requestAnimationFrame.spec';
2020
import './browser/WebSocket.spec';
2121
import './browser/XMLHttpRequest.spec';
2222
import './browser/MediaQuery.spec';
23+
import './browser/Notification.spec';
2324
import './mocha-patch.spec';

0 commit comments

Comments
 (0)