Standard timers - fix for #4384 (#4389)

Specifications define timers capable of accepting optional parameters.
https://www.w3.org/TR/2011/WD-html5-20110525/timers.html#timers

This PR goal is to standardize such behavior in NativeScript too.
This commit is contained in:
Andrea Giammarchi
2017-06-15 21:19:49 +01:00
committed by Alexander Vakrilov
parent 9866350559
commit 7e39bfb9d4
4 changed files with 51 additions and 10 deletions

View File

@@ -14,9 +14,10 @@ function createHandlerAndGetId(): number {
return timerId;
}
export function setTimeout(callback: Function, milliseconds = 0): number {
export function setTimeout(callback: Function, milliseconds = 0, ...args): number {
const id = createHandlerAndGetId();
const zoneBound = zonedCallback(callback);
const invoke = () => callback(...args);
const zoneBound = zonedCallback(invoke);
var runnable = new java.lang.Runnable({
run: () => {
@@ -45,10 +46,11 @@ export function clearTimeout(id: number): void {
}
}
export function setInterval(callback: Function, milliseconds = 0): number {
export function setInterval(callback: Function, milliseconds = 0, ...args): number {
const id = createHandlerAndGetId();
const handler = timeoutHandler;
const zoneBound = zonedCallback(callback);
const invoke = () => callback(...args);
const zoneBound = zonedCallback(invoke);
var runnable = new java.lang.Runnable({
run: () => {