globals module added with setTimeout implementation for both iOS and Android

This commit is contained in:
Vladimir Enchev
2014-05-10 13:15:37 +03:00
parent 44c51a0e48
commit 2d701fb5a4
7 changed files with 39 additions and 8 deletions

View File

@@ -169,6 +169,14 @@
<TypeScriptCompile Include="promises\index.ts" /> <TypeScriptCompile Include="promises\index.ts" />
<TypeScriptCompile Include="http\http.ts" /> <TypeScriptCompile Include="http\http.ts" />
<TypeScriptCompile Include="ios7.d.ts" /> <TypeScriptCompile Include="ios7.d.ts" />
<TypeScriptCompile Include="globals\globals.android.ts">
<DependentUpon>globals.d.ts</DependentUpon>
</TypeScriptCompile>
<TypeScriptCompile Include="globals\globals.d.ts" />
<TypeScriptCompile Include="globals\globals.ios.ts">
<DependentUpon>globals.d.ts</DependentUpon>
</TypeScriptCompile>
<TypeScriptCompile Include="globals\index.ts" />
<Content Include="_references.ts" /> <Content Include="_references.ts" />
<TypeScriptCompile Include="Console\console.d.ts" /> <TypeScriptCompile Include="Console\console.d.ts" />
<Content Include="Image\Readme.md" /> <Content Include="Image\Readme.md" />

View File

@@ -22,11 +22,3 @@
return arr; return arr;
} }
} }
export function setTimeout(callback, milliseconds) {
new android.os.Handler(android.os.Looper.getMainLooper()).postDelayed(
new java.lang.Runnable({
run: function () { callback(); }
}),
milliseconds);
}

5
globals/Readme.md Normal file
View File

@@ -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);
```

View File

@@ -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));
}

4
globals/globals.d.ts vendored Normal file
View File

@@ -0,0 +1,4 @@
/**
* global functions.
*/
export declare function setTimeout(callback: Function, milliseconds: number): void;

7
globals/globals.ios.ts Normal file
View File

@@ -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);
}

5
globals/index.ts Normal file
View File

@@ -0,0 +1,5 @@
declare var module, setTimeout;
import globals = require("globals/globals");
module.exports = globals;
setTimeout = globals.setTimeout;