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

Commit

Permalink
refactor to use _global from _load_patch
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaLiPassion committed Jul 13, 2017
1 parent ead74a1 commit 8a15c66
Show file tree
Hide file tree
Showing 6 changed files with 363 additions and 354 deletions.
2 changes: 1 addition & 1 deletion lib/browser/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Zone.__load_patch('EventTarget', (global: any, Zone: ZoneType, api: _ZonePrivate
});

Zone.__load_patch('on_property', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
propertyDescriptorPatch(global);
propertyDescriptorPatch(api, global);
propertyPatch();
registerElementPatch(global);
});
Expand Down
7 changes: 4 additions & 3 deletions lib/browser/event-target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {FALSE_STR, globalSources, patchEventTargetMethods, TRUE_STR, ZONE_SYMBOL_PREFIX, zoneSymbolEventNames} from '../common/events';
import {FALSE_STR, globalSources, patchEventTarget, TRUE_STR, ZONE_SYMBOL_PREFIX, zoneSymbolEventNames} from '../common/events';
import {attachOriginToPatched, isIEOrEdge, zoneSymbol} from '../common/utils';

import {eventNames} from './property-descriptor';
Expand Down Expand Up @@ -96,11 +96,12 @@ export function eventTargetPatch(_global: any, api: _ZonePrivate) {
return true;
};

const apiTypes: any[] = [];
for (let i = 0; i < apis.length; i++) {
const type = _global[apis[i]];
patchEventTargetMethods(type && type.prototype, {validateHandler: checkIEAndCrossContext});
apiTypes.push(type && type.prototype);
}
patchEventTarget(api, _global, apiTypes, {validateHandler: checkIEAndCrossContext});

api.patchEventTargetMethods = patchEventTargetMethods;
return true;
}
4 changes: 2 additions & 2 deletions lib/browser/property-descriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export const eventNames = globalEventHandlersEventNames.concat(
webglEventNames, formEventNames, detailEventNames, documentEventNames, windowEventNames,
htmlElementEventNames, ieElementEventNames);

export function propertyDescriptorPatch(_global: any) {
export function propertyDescriptorPatch(api: _ZonePrivate, _global: any) {
if (isNode && !isMix) {
return;
}
Expand Down Expand Up @@ -279,7 +279,7 @@ export function propertyDescriptorPatch(_global: any) {
patchViaCapturingAllTheEvents();
patchClass('XMLHttpRequest');
if (supportsWebSocket) {
webSocketPatch.apply(_global);
webSocketPatch.apply(api, _global);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/browser/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
* found in the LICENSE file at https://angular.io/license
*/

import {patchEventTargetMethods} from '../common/events';
import {patchEventTarget} from '../common/events';
import {patchOnProperties} from '../common/utils';

// we have to patch the instance since the proto is non-configurable
export function apply(_global: any) {
export function apply(api: _ZonePrivate, _global: any) {
const WS = (<any>_global).WebSocket;
// On Safari window.EventTarget doesn't exist so need to patch WS add/removeEventListener
// On older Chrome, no need since EventTarget was already patched
if (!(<any>_global).EventTarget) {
patchEventTargetMethods(WS.prototype);
patchEventTarget(api, _global, [WS.prototype]);
}
(<any>_global).WebSocket = function(a: any, b: any) {
const socket = arguments.length > 1 ? new WS(a, b) : new WS(a);
Expand Down
Loading

0 comments on commit 8a15c66

Please sign in to comment.