From 5f0e3fdc58de72524622edbd9336ca048454eabc Mon Sep 17 00:00:00 2001 From: Vladimir Enchev Date: Wed, 9 Dec 2015 11:47:33 +0200 Subject: [PATCH] dialogs and timer lazy require --- globals/globals.ts | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/globals/globals.ts b/globals/globals.ts index e3235cc23..ef1986e10 100644 --- a/globals/globals.ts +++ b/globals/globals.ts @@ -16,29 +16,50 @@ if (platform.device.os === platform.platformNames.android) { global.console.dump = function (args) { c.dump(args); }; } +var tm; +function getTimer() { + if (!tm) { + tm = require("timer"); + } + + return tm; +} + global.setTimeout = function (callback, milliseconds) { - let tm = require("timer"); - return tm.setTimeout(callback, milliseconds); + return getTimer().setTimeout(callback, milliseconds); } global.clearTimeout = function (id) { - let tm = require("timer"); - tm.clearTimeout(id); + getTimer().clearTimeout(id); } global.setInterval = function (callback, milliseconds) { - let tm = require("timer"); - return tm.setInterval(callback, milliseconds); + return getTimer().setInterval(callback, milliseconds); } global.clearInterval = function (id) { - let tm = require("timer"); - tm.clearInterval(id); + getTimer().clearInterval(id); +} + +var dm; +function getDialogs() { + if (!dm) { + dm = require("ui/dialogs"); + } + + return dm; } global.alert = function (args) { - let dm = require("ui/dialogs"); - return dm.alert(args); + return getDialogs().alert(args); +} + +global.confirm = function (args) { + return getDialogs().confirm(args); +} + +global.prompt = function (args) { + return getDialogs().prompt(args); } var xhr = require("../xhr/xhr");