mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Do not use lazy requires where not needed.
This commit is contained in:
@ -12,6 +12,27 @@ import http = require("http");
|
||||
var requestIdCounter = 0;
|
||||
var pendingRequests = {};
|
||||
|
||||
var utils: typeof utilsModule;
|
||||
function ensureUtils() {
|
||||
if (!utils) {
|
||||
utils = require("utils/utils");
|
||||
}
|
||||
}
|
||||
|
||||
var imageSource: typeof imageSourceModule;
|
||||
function ensureImageSource() {
|
||||
if (!imageSource) {
|
||||
imageSource = require("image-source");
|
||||
}
|
||||
}
|
||||
|
||||
var platform: typeof platformModule;
|
||||
function ensurePlatform() {
|
||||
if (!platform) {
|
||||
platform = require("platform");
|
||||
}
|
||||
}
|
||||
|
||||
var completeCallback: com.tns.Async.CompleteCallback;
|
||||
function ensureCompleteCallback() {
|
||||
if (completeCallback) {
|
||||
@ -59,12 +80,11 @@ function onRequestComplete(requestId: number, result: com.tns.Async.Http.Request
|
||||
}
|
||||
},
|
||||
toJSON: () => {
|
||||
var utils: typeof utilsModule = require("utils/utils");
|
||||
|
||||
ensureUtils();
|
||||
return utils.parseJSON(result.responseAsString);
|
||||
},
|
||||
toImage: () => {
|
||||
var imageSource: typeof imageSourceModule = require("image-source");
|
||||
ensureImageSource();
|
||||
|
||||
return new Promise<any>((resolveImage, rejectImage) => {
|
||||
if (result.responseAsImage != null) {
|
||||
@ -111,7 +131,7 @@ function buildJavaOptions(options: http.HttpRequestOptions) {
|
||||
javaOptions.headers = arrayList;
|
||||
}
|
||||
|
||||
var platform: typeof platformModule = require("platform");
|
||||
ensurePlatform();
|
||||
|
||||
// pass the maximum available image size to the request options in case we need a bitmap conversion
|
||||
var screen = platform.screen.mainScreen;
|
||||
|
Reference in New Issue
Block a user