mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
setTimeout and setInterval are now more TypeScript like
This commit is contained in:
@ -4,7 +4,7 @@
|
|||||||
var timeoutHandler;
|
var timeoutHandler;
|
||||||
var timeoutCallbacks = {};
|
var timeoutCallbacks = {};
|
||||||
|
|
||||||
function createHadlerAndGetId() : number {
|
function createHadlerAndGetId(): number {
|
||||||
if (!timeoutHandler) {
|
if (!timeoutHandler) {
|
||||||
timeoutHandler = new android.os.Handler(android.os.Looper.getMainLooper());
|
timeoutHandler = new android.os.Handler(android.os.Looper.getMainLooper());
|
||||||
}
|
}
|
||||||
@ -16,7 +16,7 @@ export function setTimeout(callback: Function, milliseconds = 0): number {
|
|||||||
var id = createHadlerAndGetId();
|
var id = createHadlerAndGetId();
|
||||||
|
|
||||||
var runnable = new java.lang.Runnable({
|
var runnable = new java.lang.Runnable({
|
||||||
run: function () {
|
run: () => {
|
||||||
callback();
|
callback();
|
||||||
timeoutCallbacks[id] = null;
|
timeoutCallbacks[id] = null;
|
||||||
}
|
}
|
||||||
@ -42,7 +42,7 @@ export function setInterval(callback: Function, milliseconds = 0): number {
|
|||||||
var id = createHadlerAndGetId();
|
var id = createHadlerAndGetId();
|
||||||
|
|
||||||
var runnable = new java.lang.Runnable({
|
var runnable = new java.lang.Runnable({
|
||||||
run: function () {
|
run: () => {
|
||||||
callback();
|
callback();
|
||||||
timeoutHandler.postDelayed(runnable, long(milliseconds));
|
timeoutHandler.postDelayed(runnable, long(milliseconds));
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ var timeoutCallbacks = {};
|
|||||||
function createTimerAndGetId(callback: Function, milliseconds: number, shouldRepeat: boolean): number {
|
function createTimerAndGetId(callback: Function, milliseconds: number, shouldRepeat: boolean): number {
|
||||||
var id = new Date().getUTCMilliseconds();
|
var id = new Date().getUTCMilliseconds();
|
||||||
|
|
||||||
var target = Foundation.NSObject.extends({ tick: function (timer) { callback(); } }, { exposedMethods: { "tick:": "v@:@" } });
|
var target = Foundation.NSObject.extends({ tick: (timer) => { callback(); } }, { exposedMethods: { "tick:": "v@:@" } });
|
||||||
var timer = Foundation.NSTimer.scheduledTimerWithTimeIntervalTargetSelectorUserInfoRepeats(milliseconds / 1000, new target(), "tick:", null, shouldRepeat);
|
var timer = Foundation.NSTimer.scheduledTimerWithTimeIntervalTargetSelectorUserInfoRepeats(milliseconds / 1000, new target(), "tick:", null, shouldRepeat);
|
||||||
|
|
||||||
if (!timeoutCallbacks[id]) {
|
if (!timeoutCallbacks[id]) {
|
||||||
|
Reference in New Issue
Block a user