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

Commit

Permalink
fix(webcomponents): fix #782, fix conflicts with shadydom of webcompo…
Browse files Browse the repository at this point in the history
…nents (#784)

* fix(webcomponents): fix #782, fix conflicts with shadydom of webcomponents

* add doc

* use new private api method
  • Loading branch information
JiaLiPassion authored and mhevery committed May 19, 2017
1 parent 82d4133 commit 245f8e9
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 0 deletions.
12 changes: 12 additions & 0 deletions NON-STANDARD-APIS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ But there are still a lot of non standard APIs are not patched by default, such
* MediaQuery
* Notification

## Currently supported polyfills

* webcomponents

Usage:

```
<script src="webcomponents-lite.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/zone.js/dist/webapis-shadydom.js"></script>
```

## Currently supported non standard node APIs

## Currently supported non standard common APIs
Expand Down
40 changes: 40 additions & 0 deletions dist/webapis-shadydom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
(factory());
}(this, (function () { 'use strict';

/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
Zone.__load_patch('shadydom', function (global, Zone, api) {
var patchEventTargetMethods = Zone[Zone.__symbol__('patchEventTargetMethods')];
// https://github.com/angular/zone.js/issues/782
// in web components, shadydom will patch addEventListener/removeEventListener of
// Node.prototype and WindowPrototype, this will have conflict with zone.js
// so zone.js need to patch them again.
var windowPrototype = Object.getPrototypeOf(window);
if (windowPrototype && windowPrototype.hasOwnProperty('addEventListener')) {
windowPrototype[Zone.__symbol__('addEventListener')] = null;
windowPrototype[Zone.__symbol__('removeEventListener')] = null;
patchEventTargetMethods(windowPrototype);
}
if (Node.prototype.hasOwnProperty('addEventListener')) {
Node.prototype[Zone.__symbol__('addEventListener')] = null;
Node.prototype[Zone.__symbol__('removeEventListener')] = null;
patchEventTargetMethods(Node.prototype);
}
});

})));
1 change: 1 addition & 0 deletions dist/webapis-shadydom.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ gulp.task('build/webapis-notification.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/browser/webapis-notification.ts', 'webapis-notification.min.js', true, cb);
});

gulp.task('build/webapis-shadydom.js', ['compile-esm'], function(cb) {
return generateScript('./lib/browser/shadydom.ts', 'webapis-shadydom.js', false, cb);
});

gulp.task('build/webapis-shadydom.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/browser/shadydom.ts', 'webapis-shadydom.min.js', true, cb);
});

gulp.task('build/bluebird.js', ['compile-esm'], function(cb) {
return generateScript('./lib/extra/bluebird.ts', 'zone-bluebird.js', false, cb);
});
Expand Down Expand Up @@ -194,6 +202,8 @@ gulp.task('build', [
'build/webapis-media-query.min.js',
'build/webapis-notification.js',
'build/webapis-notification.min.js',
'build/webapis-shadydom.js',
'build/webapis-shadydom.min.js',
'build/zone-mix.js',
'build/bluebird.js',
'build/bluebird.min.js',
Expand Down
24 changes: 24 additions & 0 deletions lib/browser/shadydom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
Zone.__load_patch('shadydom', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
// https://github.com/angular/zone.js/issues/782
// in web components, shadydom will patch addEventListener/removeEventListener of
// Node.prototype and WindowPrototype, this will have conflict with zone.js
// so zone.js need to patch them again.
const windowPrototype = Object.getPrototypeOf(window);
if (windowPrototype && windowPrototype.hasOwnProperty('addEventListener')) {
(windowPrototype as any)[Zone.__symbol__('addEventListener')] = null;
(windowPrototype as any)[Zone.__symbol__('removeEventListener')] = null;
api.patchEventTargetMethods(windowPrototype);
}
if (Node.prototype.hasOwnProperty('addEventListener')) {
(Node.prototype as any)[Zone.__symbol__('addEventListener')] = null;
(Node.prototype as any)[Zone.__symbol__('removeEventListener')] = null;
api.patchEventTargetMethods(Node.prototype);
}
});

0 comments on commit 245f8e9

Please sign in to comment.