mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
Do not use lazy requires where not needed.
This commit is contained in:
@ -1,6 +1,13 @@
|
||||
import utils = require("utils/utils");
|
||||
import * as httpModule from "http";
|
||||
|
||||
var http: typeof httpModule;
|
||||
function ensureHttp() {
|
||||
if (!http) {
|
||||
http = require("http");
|
||||
}
|
||||
}
|
||||
|
||||
// This is used for definition purposes only, it does not generate JavaScript for it.
|
||||
import definition = require("image-source");
|
||||
|
||||
@ -30,7 +37,7 @@ export function fromNativeSource(source: any): definition.ImageSource {
|
||||
}
|
||||
|
||||
export function fromUrl(url: string): Promise<definition.ImageSource> {
|
||||
var http: typeof httpModule = require("http");
|
||||
ensureHttp();
|
||||
return http.getImage(url);
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,27 @@ import * as enumsModule from "ui/enums";
|
||||
|
||||
global.moduleMerge(common, exports);
|
||||
|
||||
var utils: typeof utilsModule;
|
||||
function ensureUtils() {
|
||||
if (!utils) {
|
||||
utils = require("utils/utils");
|
||||
}
|
||||
}
|
||||
|
||||
var fs: typeof fileSystemModule;
|
||||
function ensureFS() {
|
||||
if (!fs) {
|
||||
fs = require("file-system");
|
||||
}
|
||||
}
|
||||
|
||||
var enums: typeof enumsModule;
|
||||
function ensureEnums() {
|
||||
if (!enums) {
|
||||
enums = require("ui/enums");
|
||||
}
|
||||
}
|
||||
|
||||
export class ImageSource implements definition.ImageSource {
|
||||
public android: android.graphics.Bitmap;
|
||||
public ios: UIImage;
|
||||
@ -14,7 +35,7 @@ export class ImageSource implements definition.ImageSource {
|
||||
public loadFromResource(name: string): boolean {
|
||||
this.android = null;
|
||||
|
||||
var utils: typeof utilsModule = require("utils/utils");
|
||||
ensureUtils();
|
||||
|
||||
var res = utils.ad.getApplicationContext().getResources();
|
||||
if (res) {
|
||||
@ -32,7 +53,7 @@ export class ImageSource implements definition.ImageSource {
|
||||
}
|
||||
|
||||
public loadFromFile(path: string): boolean {
|
||||
var fs: typeof fileSystemModule = require("file-system");
|
||||
ensureFS();
|
||||
|
||||
var fileName = types.isString(path) ? path.trim() : "";
|
||||
if (fileName.indexOf("~/") === 0) {
|
||||
@ -112,7 +133,7 @@ export class ImageSource implements definition.ImageSource {
|
||||
}
|
||||
|
||||
function getTargetFromat(format: string): android.graphics.Bitmap.CompressFormat {
|
||||
var enums: typeof enumsModule = require("ui/enums");
|
||||
ensureEnums();
|
||||
|
||||
switch (format) {
|
||||
case enums.ImageFormat.jpeg:
|
||||
|
Reference in New Issue
Block a user