Commit 38725089 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(utils.js): `parent` is now a explicit parameter of `setTimeout`

parent 37e7954c
...@@ -95,7 +95,7 @@ Item { ...@@ -95,7 +95,7 @@ Item {
// call. // call.
// //
// The timeout is destroyed with the `MouseArea` component. // The timeout is destroyed with the `MouseArea` component.
_timeout = Utils.setTimeout.call( _timeout = Utils.setTimeout(
this, 0, item.pressed.bind(this) this, 0, item.pressed.bind(this)
) )
} }
......
...@@ -84,13 +84,11 @@ function snakeToCamel (s) { ...@@ -84,13 +84,11 @@ function snakeToCamel (s) {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// A copy of `Window.setTimeout` from js. // A copy of `Window.setTimeout` from js.
// Use setTimeout.call(parentContext, delayTime, cb) to use it.
//
// delay is in milliseconds. // delay is in milliseconds.
function setTimeout (delay, cb) { function setTimeout (parent, delay, cb) {
var timer = new (function (parent) { var timer = new (function (parent) {
return Qt.createQmlObject('import QtQuick 2.7; Timer { }', parent) return Qt.createQmlObject('import QtQuick 2.7; Timer { }', parent)
})(this) })(parent)
timer.interval = delay timer.interval = delay
timer.repeat = false timer.repeat = false
......
...@@ -50,7 +50,7 @@ TestCase { ...@@ -50,7 +50,7 @@ TestCase {
function test_setTimeoutWithoutParent () { function test_setTimeoutWithoutParent () {
try { try {
Utils.setTimeout(0, function () { Utils.setTimeout(null, 0, function () {
fail('`setTimeout` was called without parent.') fail('`setTimeout` was called without parent.')
}) })
} catch (e) { } catch (e) {
...@@ -67,7 +67,7 @@ TestCase { ...@@ -67,7 +67,7 @@ TestCase {
function test_setTimeout (data) { function test_setTimeout (data) {
var failed = true var failed = true
Utils.setTimeout.call(testCase, data.time, function () { Utils.setTimeout(testCase, data.time, function () {
failed = false failed = false
}) })
...@@ -93,7 +93,7 @@ TestCase { ...@@ -93,7 +93,7 @@ TestCase {
function test_clearTimeout (data) { function test_clearTimeout (data) {
var failed = false var failed = false
var timeout = Utils.setTimeout.call(testCase, data.time, function () { var timeout = Utils.setTimeout(testCase, data.time, function () {
failed = true failed = true
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment