fix(zone.js): patch shadydom (#31717)

Close #31686

PR Close #31717
This commit is contained in:
JiaLiPassion
2019-07-21 19:44:13 +09:00
committed by Miško Hevery
parent a86850e3f2
commit 35a025fbca
6 changed files with 302 additions and 185 deletions

View File

@ -10,15 +10,17 @@ Zone.__load_patch('shadydom', (global: any, Zone: ZoneType, api: _ZonePrivate) =
// 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.patchEventTarget(global, [windowPrototype]);
}
if (Node.prototype.hasOwnProperty('addEventListener')) {
(Node.prototype as any)[Zone.__symbol__('addEventListener')] = null;
(Node.prototype as any)[Zone.__symbol__('removeEventListener')] = null;
api.patchEventTarget(global, [Node.prototype]);
}
const HTMLSlotElement = global.HTMLSlotElement;
const prototypes = [
Object.getPrototypeOf(window), Node.prototype, Text.prototype, Element.prototype,
HTMLElement.prototype, HTMLSlotElement && HTMLSlotElement.prototype, DocumentFragment.prototype,
Document.prototype
];
prototypes.forEach(function(proto) {
if (proto && proto.hasOwnProperty('addEventListener')) {
proto[Zone.__symbol__('addEventListener')] = null;
proto[Zone.__symbol__('removeEventListener')] = null;
api.patchEventTarget(global, [proto]);
}
});
});