|
| 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. |
0 commit comments