From 2d701fb5a4236fb88a84b7de43e11503af0ba793 Mon Sep 17 00:00:00 2001 From: Vladimir Enchev Date: Sat, 10 May 2014 13:15:37 +0300 Subject: [PATCH] globals module added with setTimeout implementation for both iOS and Android --- BCL.csproj | 8 ++++++++ Utils/utils_android.ts | 8 -------- globals/Readme.md | 5 +++++ globals/globals.android.ts | 10 ++++++++++ globals/globals.d.ts | 4 ++++ globals/globals.ios.ts | 7 +++++++ globals/index.ts | 5 +++++ 7 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 globals/Readme.md create mode 100644 globals/globals.android.ts create mode 100644 globals/globals.d.ts create mode 100644 globals/globals.ios.ts create mode 100644 globals/index.ts diff --git a/BCL.csproj b/BCL.csproj index ae40c527a..5a29178e9 100644 --- a/BCL.csproj +++ b/BCL.csproj @@ -169,6 +169,14 @@ + + globals.d.ts + + + + globals.d.ts + + diff --git a/Utils/utils_android.ts b/Utils/utils_android.ts index ceed383ed..3acfe9f2f 100644 --- a/Utils/utils_android.ts +++ b/Utils/utils_android.ts @@ -21,12 +21,4 @@ return arr; } -} - -export function setTimeout(callback, milliseconds) { - new android.os.Handler(android.os.Looper.getMainLooper()).postDelayed( - new java.lang.Runnable({ - run: function () { callback(); } - }), - milliseconds); } \ No newline at end of file diff --git a/globals/Readme.md b/globals/Readme.md new file mode 100644 index 000000000..bbc16208f --- /dev/null +++ b/globals/Readme.md @@ -0,0 +1,5 @@ +Globals module for defining functions part of the global context. For example setTimeout: +```js + require("globals"); + setTimeout(function(){ log("Test"); }, 2000); +``` \ No newline at end of file diff --git a/globals/globals.android.ts b/globals/globals.android.ts new file mode 100644 index 000000000..717a74fbc --- /dev/null +++ b/globals/globals.android.ts @@ -0,0 +1,10 @@ +/** + * Android specific global functions implementation. + */ +export function setTimeout(callback: Function, milliseconds: number): void { + new android.os.Handler(android.os.Looper.getMainLooper()).postDelayed( + new java.lang.Runnable({ + run: function () { callback(); } + }), + long(milliseconds)); +} diff --git a/globals/globals.d.ts b/globals/globals.d.ts new file mode 100644 index 000000000..953ce8ffa --- /dev/null +++ b/globals/globals.d.ts @@ -0,0 +1,4 @@ +/** + * global functions. + */ +export declare function setTimeout(callback: Function, milliseconds: number): void; diff --git a/globals/globals.ios.ts b/globals/globals.ios.ts new file mode 100644 index 000000000..0492a6e2d --- /dev/null +++ b/globals/globals.ios.ts @@ -0,0 +1,7 @@ +/** + * iOS specific global functions implementation. + */ +export function setTimeout(callback: Function, milliseconds: number): void { + var target = Foundation.NSObject.extends({ tick: function (timer) { callback(); } }, { exposedMethods: { "tick:": "v@:@" } }); + Foundation.NSTimer.scheduledTimerWithTimeIntervalTargetSelectorUserInfoRepeats(milliseconds / 1000, new target(), "tick:", null, false); +} diff --git a/globals/index.ts b/globals/index.ts new file mode 100644 index 000000000..b7cd37955 --- /dev/null +++ b/globals/index.ts @@ -0,0 +1,5 @@ +declare var module, setTimeout; +import globals = require("globals/globals"); +module.exports = globals; + +setTimeout = globals.setTimeout; \ No newline at end of file