MCPcopy Create free account
hub / github.com/angular/angular / patchCordova

Function patchCordova

packages/zone.js/lib/extra/cordova.ts:11–50  ·  view source on GitHub ↗
(Zone: ZoneType)

Source from the content-addressed store, hash-verified

9import {ZoneType} from '../zone-impl';
10
11export function patchCordova(Zone: ZoneType): void {
12 Zone.__load_patch('cordova', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
13 if (global.cordova) {
14 const SUCCESS_SOURCE = 'cordova.exec.success';
15 const ERROR_SOURCE = 'cordova.exec.error';
16 const FUNCTION = 'function';
17 const nativeExec: Function | null = api.patchMethod(
18 global.cordova,
19 'exec',
20 () =>
21 function (self: any, args: any[]) {
22 if (args.length > 0 && typeof args[0] === FUNCTION) {
23 args[0] = Zone.current.wrap(args[0], SUCCESS_SOURCE);
24 }
25 if (args.length > 1 && typeof args[1] === FUNCTION) {
26 args[1] = Zone.current.wrap(args[1], ERROR_SOURCE);
27 }
28 return nativeExec!.apply(self, args);
29 },
30 );
31 }
32 });
33
34 Zone.__load_patch('cordova.FileReader', (global: any, Zone: ZoneType) => {
35 if (global.cordova && typeof global['FileReader'] !== 'undefined') {
36 document.addEventListener('deviceReady', () => {
37 const FileReader = global['FileReader'];
38 ['abort', 'error', 'load', 'loadstart', 'loadend', 'progress'].forEach((prop) => {
39 const eventNameSymbol = Zone.__symbol__('ON_PROPERTY' + prop);
40 Object.defineProperty(FileReader.prototype, eventNameSymbol, {
41 configurable: true,
42 get: function () {
43 return this._realReader && this._realReader[eventNameSymbol];
44 },
45 });
46 });
47 });
48 }
49 });
50}

Callers 1

rollup-cordova.tsFile · 0.90

Calls 6

__symbol__Method · 0.80
__load_patchMethod · 0.65
wrapMethod · 0.65
applyMethod · 0.65
addEventListenerMethod · 0.65
forEachMethod · 0.45

Tested by

no test coverage detected