Skip to content

Commit 6b34841

Browse files
committed
chore: re-add zone files
1 parent 277140f commit 6b34841

10 files changed

Lines changed: 15098 additions & 10683 deletions

File tree

package-lock.json

Lines changed: 14221 additions & 10683 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* eslint-disable */
2+
import './core';
3+
import { Connectivity } from '@nativescript/core';
4+
5+
Zone.__load_patch('nativescript_connectivity', (global, zone, api) => {
6+
api.patchMethod(
7+
Connectivity,
8+
'startMonitoring',
9+
(delegate, delegateName, name) =>
10+
function (self, args) {
11+
const callback = args[0];
12+
return delegate.apply(self, [Zone.current.wrap(callback, 'NS Connectivity patch')]);
13+
},
14+
);
15+
});

packages/zone-js/dist/core.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* eslint-disable */
2+
import { patchClass, patchNativeScriptEventTarget } from './utils';
3+
4+
function isPropertyWritable(propertyDesc: any) {
5+
if (!propertyDesc) {
6+
return true;
7+
}
8+
9+
if (propertyDesc.writable === false) {
10+
return false;
11+
}
12+
13+
return !(typeof propertyDesc.get === 'function' && typeof propertyDesc.set === 'undefined');
14+
}
15+
16+
Zone.__load_patch('nativescript_patchMethod', (global, Zone, api) => {
17+
api.patchMethod = function patchMethod(
18+
target: any,
19+
name: string,
20+
patchFn: (delegate: Function, delegateName: string, name: string) => (self: any, args: any[]) => any,
21+
): Function | null {
22+
let proto = target;
23+
while (proto && !proto.hasOwnProperty(name)) {
24+
proto = Object.getPrototypeOf(proto);
25+
}
26+
if (!proto && target[name]) {
27+
// somehow we did not find it, but we can see it. This happens on IE for Window properties.
28+
proto = target;
29+
}
30+
31+
const delegateName = Zone.__symbol__(name);
32+
let delegate: Function | null = null;
33+
if (proto && !proto.hasOwnProperty(delegateName)) {
34+
delegate = proto[delegateName] = proto[name];
35+
// check whether proto[name] is writable
36+
// some property is readonly in safari, such as HtmlCanvasElement.prototype.toBlob
37+
const desc = proto && api.ObjectGetOwnPropertyDescriptor(proto, name);
38+
if (isPropertyWritable(desc)) {
39+
const patchDelegate = patchFn(delegate!, delegateName, name);
40+
proto[name] = function () {
41+
return patchDelegate(this, arguments as any);
42+
};
43+
api.attachOriginToPatched(proto[name], delegate);
44+
// if (shouldCopySymbolProperties) {
45+
// copySymbolProperties(delegate, proto[name]);
46+
// }
47+
}
48+
}
49+
return delegate;
50+
};
51+
});
52+
53+
Zone.__load_patch('nativescript_event_target_api', (g, z, api: any) => {
54+
api.patchNativeScriptEventTarget = patchNativeScriptEventTarget;
55+
});
56+
57+
Zone.__load_patch('nativescript_patch_class_api', (g, z, api) => {
58+
api.patchClass = (className: string) => patchClass(className, api);
59+
});
60+
61+
// Initialize zone microtask queue on main thread
62+
// TODO: dive into the ios runtime (PromiseProxy) and find a better solution
63+
Promise.resolve().then(() => {});

packages/zone-js/dist/events.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* eslint-disable */
2+
import './core';
3+
import { Observable, View, Utils } from '@nativescript/core';
4+
5+
Zone.__load_patch('nativescript_observable_events', (g, z, api: any) => {
6+
api.patchNativeScriptEventTarget(g, api, [Observable, Observable.prototype, View, View.prototype]);
7+
});
8+
9+
Zone.__load_patch('nativescript_xhr_events', (g, z, api: any) => {
10+
api.patchNativeScriptEventTarget(g, api, [XMLHttpRequest.prototype]);
11+
});
12+
13+
// We're patching the Utils object instead of the actual js module
14+
Zone.__load_patch('nativescript_mainThreadify', (global, zone, api) => {
15+
api.patchMethod(
16+
Utils,
17+
'mainThreadify',
18+
(delegate, delegateName, name) =>
19+
function (self, args) {
20+
const callback = args[0];
21+
return delegate.apply(self, [Zone.current.wrap(callback, 'NS mainThreadify patch')]);
22+
},
23+
);
24+
});
25+
26+
Zone.__load_patch('nativescript_executeOnMainThread', (global, zone, api) => {
27+
api.patchMethod(
28+
Utils,
29+
'executeOnMainThread',
30+
(delegate, delegateName, name) =>
31+
function (self, args) {
32+
const callback = args[0];
33+
return delegate.apply(self, [Zone.current.wrap(callback, 'NS executeOnMainThread patch')]);
34+
},
35+
);
36+
});
37+
38+
Zone.__load_patch('nativescript_dispatchToMainThread', (global, zone, api) => {
39+
api.patchMethod(
40+
Utils,
41+
'dispatchToMainThread',
42+
(delegate, delegateName, name) =>
43+
function (self, args) {
44+
const callback = args[0];
45+
return delegate.apply(self, [Zone.current.wrap(callback, 'NS dispatchToMainThread patch')]);
46+
},
47+
);
48+
});
49+
50+
Zone.__load_patch('nativescript_showModal', (global, zone, api) => {
51+
api.patchMethod(
52+
View.prototype,
53+
'showModal',
54+
(delegate, delegateName, name) =>
55+
function (self, args) {
56+
if (args.length === 2) {
57+
const options = args[1];
58+
if (options.closeCallback) {
59+
options.closeCallback = Zone.current.wrap(options.closeCallback, 'NS showModal patch');
60+
}
61+
} else if (args.length > 3) {
62+
args[3] = Zone.current.wrap(args[3], 'NS showModal patch');
63+
}
64+
return delegate.apply(self, args);
65+
},
66+
);
67+
});
68+
69+
//! queueMacroTask should never be patched! We should consider it as a low level API to queue macroTasks which will be patched separately by other patches.

packages/zone-js/dist/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import './core';
2+
import './nativescript-globals';
3+
import './events';
4+
import './xhr';
5+
import './connectivity';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Zone.__load_patch('nativescript_MutationObserver', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
2+
// api.patchClass('MutationObserver');
3+
// api.patchClass('WebKitMutationObserver');
4+
// });
5+
6+
// Zone.__load_patch('nativescript_IntersectionObserver', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
7+
// api.patchClass('IntersectionObserver');
8+
// });
9+
10+
/* eslint-disable @typescript-eslint/no-explicit-any */
11+
Zone.__load_patch('nativescript_FileReader', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
12+
const reader = global['FileReader'];
13+
if (reader) {
14+
reader.prototype.onload = reader.prototype.onload || null;
15+
reader.prototype.onerror = reader.prototype.onerror || null;
16+
reader.prototype.onabort = reader.prototype.onabort || null;
17+
reader.prototype.onloadend = reader.prototype.onloadend || null;
18+
reader.prototype.onloadstart = reader.prototype.onloadstart || null;
19+
reader.prototype.onprogress = reader.prototype.onprogress || null;
20+
}
21+
api.patchClass('FileReader');
22+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const disabledPatches = [
2+
'legacy',
3+
'EventTarget',
4+
'XHR',
5+
'MutationObserver',
6+
'IntersectionObserver',
7+
'FileReader',
8+
];
9+
10+
for (const patch of disabledPatches) {
11+
global[`__Zone_disable_${patch}`] = true;
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* eslint-disable */
2+
import { Trace } from '@nativescript/core';
3+
4+
Zone.__load_patch('nativescript_zone_to_trace_error', (global, zone, api) => {
5+
zone[zone.__symbol__('unhandledPromiseRejectionHandler')] = (e) => {
6+
Trace.error(e);
7+
};
8+
zone[zone.__symbol__('ignoreConsoleErrorUncaughtError')] = true;
9+
});

0 commit comments

Comments
 (0)