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

Commit 97c03b5

Browse files
JiaLiPassionmhevery
authored andcommitted
feat(patch): load non standard api with new load module method (#764)
1 parent bb6aadc commit 97c03b5

File tree

3 files changed

+45
-56
lines changed

3 files changed

+45
-56
lines changed

lib/browser/webapis-media-query.ts

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,35 @@
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-
((_global: any) => {
9-
// patch MediaQuery
10-
patchMediaQuery(_global);
11-
12-
function patchMediaQuery(_global: any) {
13-
if (!_global['MediaQueryList']) {
14-
return;
15-
}
16-
const patchEventTargetMethods =
17-
(Zone as any)[(Zone as any).__symbol__('patchEventTargetMethods')];
18-
patchEventTargetMethods(
19-
_global['MediaQueryList'].prototype, 'addListener', 'removeListener',
20-
(self: any, args: any[]) => {
21-
return {
22-
useCapturing: false,
23-
eventName: 'mediaQuery',
24-
handler: args[0],
25-
target: self || _global,
26-
name: 'mediaQuery',
27-
invokeAddFunc: function(addFnSymbol: any, delegate: any) {
28-
if (delegate && (<Task>delegate).invoke) {
29-
return this.target[addFnSymbol]((<Task>delegate).invoke);
30-
} else {
31-
return this.target[addFnSymbol](delegate);
32-
}
33-
},
34-
invokeRemoveFunc: function(removeFnSymbol: any, delegate: any) {
35-
if (delegate && (<Task>delegate).invoke) {
36-
return this.target[removeFnSymbol]((<Task>delegate).invoke);
37-
} else {
38-
return this.target[removeFnSymbol](delegate);
39-
}
40-
}
41-
};
42-
});
8+
Zone.__load_patch('mediaQuery', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
9+
if (!global['MediaQueryList']) {
10+
return;
4311
}
44-
})(typeof window === 'object' && window || typeof self === 'object' && self || global);
12+
const patchEventTargetMethods =
13+
(Zone as any)[(Zone as any).__symbol__('patchEventTargetMethods')];
14+
patchEventTargetMethods(
15+
_global['MediaQueryList'].prototype, 'addListener', 'removeListener',
16+
(self: any, args: any[]) => {
17+
return {
18+
useCapturing: false,
19+
eventName: 'mediaQuery',
20+
handler: args[0],
21+
target: self || global,
22+
name: 'mediaQuery',
23+
invokeAddFunc: function(addFnSymbol: any, delegate: any) {
24+
if (delegate && (<Task>delegate).invoke) {
25+
return this.target[addFnSymbol]((<Task>delegate).invoke);
26+
} else {
27+
return this.target[addFnSymbol](delegate);
28+
}
29+
},
30+
invokeRemoveFunc: function(removeFnSymbol: any, delegate: any) {
31+
if (delegate && (<Task>delegate).invoke) {
32+
return this.target[removeFnSymbol]((<Task>delegate).invoke);
33+
} else {
34+
return this.target[removeFnSymbol](delegate);
35+
}
36+
}
37+
};
38+
});
39+
});

lib/browser/webapis-notification.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,15 @@
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-
((_global: any) => {
9-
// patch Notification
10-
patchNotification(_global);
11-
12-
function patchNotification(_global: any) {
13-
const Notification = _global['Notification'];
14-
if (!Notification || !Notification.prototype) {
15-
return;
16-
}
17-
const desc = Object.getOwnPropertyDescriptor(Notification.prototype, 'onerror');
18-
if (!desc || !desc.configurable) {
19-
return;
20-
}
21-
const patchOnProperties = (Zone as any)[(Zone as any).__symbol__('patchOnProperties')];
22-
patchOnProperties(Notification.prototype, null);
8+
Zone.__load_patch('notification', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
9+
const Notification = _global['Notification'];
10+
if (!Notification || !Notification.prototype) {
11+
return;
2312
}
24-
})(typeof window === 'object' && window || typeof self === 'object' && self || global);
13+
const desc = Object.getOwnPropertyDescriptor(Notification.prototype, 'onerror');
14+
if (!desc || !desc.configurable) {
15+
return;
16+
}
17+
const patchOnProperties = (Zone as any)[(Zone as any).__symbol__('patchOnProperties')];
18+
patchOnProperties(Notification.prototype, null);
19+
});

lib/extra/bluebird.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
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-
(() => {
9-
const __symbol__ = (Zone as any).__symbol__;
8+
Zone.__load_patch('bluebird', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
109
// TODO: @JiaLiPassion, we can automatically patch bluebird
1110
// if global.Promise = Bluebird, but sometimes in nodejs,
1211
// global.Promise is not Bluebird, and Bluebird is just be
1312
// used by other libraries such as sequelize, so I think it is
1413
// safe to just expose a method to patch Bluebird explicitly
15-
(Zone as any)[__symbol__('bluebird')] = function patchBluebird(Bluebird: any) {
14+
(Zone as any)[Zone.__symbol__('bluebird')] = function patchBluebird(Bluebird: any) {
1615
Bluebird.setScheduler((fn: Function) => {
1716
Zone.current.scheduleMicroTask('bluebird', fn);
1817
});
1918
};
20-
})();
19+
});

0 commit comments

Comments
 (0)