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

Commit 245f8e9

Browse files
JiaLiPassionmhevery
authored andcommitted
fix(webcomponents): fix #782, fix conflicts with shadydom of webcomponents (#784)
* fix(webcomponents): fix #782, fix conflicts with shadydom of webcomponents * add doc * use new private api method
1 parent 82d4133 commit 245f8e9

File tree

5 files changed

+87
-0
lines changed

5 files changed

+87
-0
lines changed

Diff for: NON-STANDARD-APIS.md

+12
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ But there are still a lot of non standard APIs are not patched by default, such
1111
* MediaQuery
1212
* Notification
1313

14+
## Currently supported polyfills
15+
16+
* webcomponents
17+
18+
Usage:
19+
20+
```
21+
<script src="webcomponents-lite.js"></script>
22+
<script src="node_modules/zone.js/dist/zone.js"></script>
23+
<script src="node_modules/zone.js/dist/webapis-shadydom.js"></script>
24+
```
25+
1426
## Currently supported non standard node APIs
1527

1628
## Currently supported non standard common APIs

Diff for: dist/webapis-shadydom.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
(function (global, factory) {
9+
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
10+
typeof define === 'function' && define.amd ? define(factory) :
11+
(factory());
12+
}(this, (function () { 'use strict';
13+
14+
/**
15+
* @license
16+
* Copyright Google Inc. All Rights Reserved.
17+
*
18+
* Use of this source code is governed by an MIT-style license that can be
19+
* found in the LICENSE file at https://angular.io/license
20+
*/
21+
Zone.__load_patch('shadydom', function (global, Zone, api) {
22+
var patchEventTargetMethods = Zone[Zone.__symbol__('patchEventTargetMethods')];
23+
// https://github.com/angular/zone.js/issues/782
24+
// in web components, shadydom will patch addEventListener/removeEventListener of
25+
// Node.prototype and WindowPrototype, this will have conflict with zone.js
26+
// so zone.js need to patch them again.
27+
var windowPrototype = Object.getPrototypeOf(window);
28+
if (windowPrototype && windowPrototype.hasOwnProperty('addEventListener')) {
29+
windowPrototype[Zone.__symbol__('addEventListener')] = null;
30+
windowPrototype[Zone.__symbol__('removeEventListener')] = null;
31+
patchEventTargetMethods(windowPrototype);
32+
}
33+
if (Node.prototype.hasOwnProperty('addEventListener')) {
34+
Node.prototype[Zone.__symbol__('addEventListener')] = null;
35+
Node.prototype[Zone.__symbol__('removeEventListener')] = null;
36+
patchEventTargetMethods(Node.prototype);
37+
}
38+
});
39+
40+
})));

Diff for: dist/webapis-shadydom.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

+10
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ gulp.task('build/webapis-notification.min.js', ['compile-esm'], function(cb) {
115115
return generateScript('./lib/browser/webapis-notification.ts', 'webapis-notification.min.js', true, cb);
116116
});
117117

118+
gulp.task('build/webapis-shadydom.js', ['compile-esm'], function(cb) {
119+
return generateScript('./lib/browser/shadydom.ts', 'webapis-shadydom.js', false, cb);
120+
});
121+
122+
gulp.task('build/webapis-shadydom.min.js', ['compile-esm'], function(cb) {
123+
return generateScript('./lib/browser/shadydom.ts', 'webapis-shadydom.min.js', true, cb);
124+
});
125+
118126
gulp.task('build/bluebird.js', ['compile-esm'], function(cb) {
119127
return generateScript('./lib/extra/bluebird.ts', 'zone-bluebird.js', false, cb);
120128
});
@@ -194,6 +202,8 @@ gulp.task('build', [
194202
'build/webapis-media-query.min.js',
195203
'build/webapis-notification.js',
196204
'build/webapis-notification.min.js',
205+
'build/webapis-shadydom.js',
206+
'build/webapis-shadydom.min.js',
197207
'build/zone-mix.js',
198208
'build/bluebird.js',
199209
'build/bluebird.min.js',

Diff for: lib/browser/shadydom.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
Zone.__load_patch('shadydom', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
9+
// https://github.com/angular/zone.js/issues/782
10+
// in web components, shadydom will patch addEventListener/removeEventListener of
11+
// Node.prototype and WindowPrototype, this will have conflict with zone.js
12+
// so zone.js need to patch them again.
13+
const windowPrototype = Object.getPrototypeOf(window);
14+
if (windowPrototype && windowPrototype.hasOwnProperty('addEventListener')) {
15+
(windowPrototype as any)[Zone.__symbol__('addEventListener')] = null;
16+
(windowPrototype as any)[Zone.__symbol__('removeEventListener')] = null;
17+
api.patchEventTargetMethods(windowPrototype);
18+
}
19+
if (Node.prototype.hasOwnProperty('addEventListener')) {
20+
(Node.prototype as any)[Zone.__symbol__('addEventListener')] = null;
21+
(Node.prototype as any)[Zone.__symbol__('removeEventListener')] = null;
22+
api.patchEventTargetMethods(Node.prototype);
23+
}
24+
});

0 commit comments

Comments
 (0)