FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(timer): setTimeout/setInterval support for boolean period (#7569) · NativeScript/NativeScript@a569bb2 · GitHub

Commit a569bb2

Browse files
authored andcommitted
fix(timer): setTimeout/setInterval support for boolean period (#7569)
* Fix setTimeout/setInterval can't be called with boolean period * Add typings and a test * Revert typings * Ignore the wrong type
1 parent 7805808 commit a569bb2

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎tests/app/timer/timer-tests.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,23 @@ export function test_setTimeout_callbackCalledAfterSpecifiedTime() {
7272
TKUnit.assert(completed, "Callback should be called after the specified time!");
7373
}
7474

75+
export function test_setTimeout_callbackCalledWithBooleanPeriod() {
76+
let completed = false;
77+
78+
// >> timer-set-false
79+
const id = timer.setTimeout(() => {
80+
// >> (hide)
81+
completed = true;
82+
// << (hide)
83+
// @ts-ignore
84+
}, false);
85+
// << timer-set-false
86+
87+
TKUnit.waitUntilReady(() => completed, 1);
88+
timer.clearTimeout(id);
89+
TKUnit.assert(completed, "Callback should be called in 0 seconds!");
90+
}
91+
7592
export function test_setTimeout_callbackNotCalled() {
7693
let completed = false;
7794

‎tns-core-modules/timer/timer.android.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ function createHandlerAndGetId(): number {
1616
}
1717

1818
export function setTimeout(callback: Function, milliseconds = 0, ...args): number {
19+
// Cast to Number
20+
milliseconds += 0;
21+
1922
const id = createHandlerAndGetId();
2023
const invoke = () => callback(...args);
2124
const zoneBound = zonedCallback(invoke);
@@ -48,6 +51,9 @@ export function clearTimeout(id: number): void {
4851
}
4952

5053
export function setInterval(callback: Function, milliseconds = 0, ...args): number {
54+
// Cast to Number
55+
milliseconds += 0;
56+
5157
const id = createHandlerAndGetId();
5258
const handler = timeoutHandler;
5359
const invoke = () => callback(...args);

‎tns-core-modules/timer/timer.ios.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class TimerTargetImpl extends NSObject {
4848
}
4949

5050
function createTimerAndGetId(callback: Function, milliseconds: number, shouldRepeat: boolean): number {
51+
// Cast to Number
52+
milliseconds += 0;
53+
5154
timerId++;
5255
let id = timerId;
5356
let timerTarget = TimerTargetImpl.initWithCallback(callback, id, shouldRepeat);

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL