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

Commit ffc298e

Browse files
JiaLiPassionmhevery
authored andcommitted
fix(webapi): refactor webapi to not import util.ts directly
Closes #652
1 parent 2d30914 commit ffc298e

File tree

7 files changed

+51
-12
lines changed

7 files changed

+51
-12
lines changed

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/bluebird.js', ['compile-esm'], function(cb) {
@@ -173,7 +181,9 @@ gulp.task('build', [
173181
'build/zone.min.js',
174182
'build/zone-node.js',
175183
'build/webapis-media-query.js',
184+
'build/webapis-media-query.min.js',
176185
'build/webapis-notification.js',
186+
'build/webapis-notification.min.js',
177187
'build/zone-mix.js',
178188
'build/bluebird.js',
179189
'build/bluebird.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

+5-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,11 @@ import {patchOnProperties} from '../common/utils';
1614
if (!Notification || !Notification.prototype) {
1715
return;
1816
}
19-
17+
const desc = Object.getOwnPropertyDescriptor(Notification.prototype, 'onerror');
18+
if (!desc || !desc.configurable) {
19+
return;
20+
}
21+
const patchOnProperties = Zone[Zone['__symbol__']('patchOnProperties')];
2022
patchOnProperties(Notification.prototype, null);
2123
}
2224
})(typeof window === 'object' && window || typeof self === 'object' && self || global);

Diff for: lib/common/utils.ts

+2
Original file line numberDiff line numberDiff line change
@@ -569,3 +569,5 @@ export function findEventTask(target: any, evtName: string): Task[] {
569569
}
570570
return result;
571571
}
572+
573+
Zone[zoneSymbol('patchEventTargetMethods')] = patchEventTargetMethods;

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

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
function notificationSupport() {
15+
const desc = window['Notification'] &&
16+
Object.getOwnPropertyDescriptor(window['Notification'].prototype, 'onerror');
17+
return window['Notification'] && window['Notification'].prototype && desc.configurable;
18+
}
19+
20+
(<any>notificationSupport).message = 'Notification Support';
21+
22+
describe('Notification API', ifEnvSupports(notificationSupport, function() {
23+
it('Notification API should be patched by Zone', () => {
24+
const Notification = window['Notification'];
25+
expect(Notification.prototype[zoneSymbol('addEventListener')]).toBeTruthy();
26+
});
27+
}));

Diff for: test/browser_entry_point.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ 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';
2425
import './jasmine-patch.spec';

0 commit comments

Comments
 (0)