Skip to content

Commit

Permalink
All timeout/interval functions are replaced with hammerhead.browserNa…
Browse files Browse the repository at this point in the history
…tives analogues (closes #431) (#737)

* All timeout/interval functions are replaced with hammerhead.browserNatives analogues (closes #431)

* fix missed window.setTimeout

* eslint rule added

* src/client/browser .eslintrc file updated
  • Loading branch information
helen-dikareva authored and AlexanderMoskovkin committed Aug 31, 2016
1 parent 0c689e1 commit f4105dc
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"dom-walk": "^0.1.1",
"error-stack-parser": "^1.3.3",
"eslint-plugin-babel": "^3.1.0",
"eslint-plugin-hammerhead": "0.0.5",
"eslint-plugin-hammerhead": "0.0.6",
"eslint-plugin-import": "^1.14.0",
"express": "^4.13.3",
"gulp": "^3.9.0",
Expand Down
3 changes: 2 additions & 1 deletion src/client/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"rules": {
"hammerhead/use-hh-promise": 2
"hammerhead/use-hh-promise": 2,
"hammerhead/use-native-methods": [2, ["setTimeout", "setInterval", "clearTimeout", "clearInterval"]]
},
"env": {
"browser": true,
Expand Down
3 changes: 2 additions & 1 deletion src/client/browser/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"rules": {
"hammerhead/use-hh-promise": 0
"hammerhead/use-hh-promise": 0,
"hammerhead/use-native-methods": 0
}
}
2 changes: 1 addition & 1 deletion src/client/core/page-unload-barrier.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function handleBeforeUnload () {

function prolongUnloadWaiting (timeout) {
if (waitingForUnloadTimeoutId)
window.clearTimeout(waitingForUnloadTimeoutId);
nativeMethods.clearTimeout.call(window, waitingForUnloadTimeoutId);

waitingForUnloadTimeoutId = nativeMethods.setTimeout.call(window, () => {
waitingForUnloadTimeoutId = null;
Expand Down
4 changes: 2 additions & 2 deletions src/client/core/prevent-real-events.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { utils, eventSandbox } from './deps/hammerhead';
import { utils, eventSandbox, nativeMethods } from './deps/hammerhead';

import { get, hasDimensions } from './utils/style';
import { filter } from './utils/array';
Expand Down Expand Up @@ -53,7 +53,7 @@ function preventRealEventHandler (e, dispatched, preventDefault, cancelHandlers,

if (isElementInvisible || invisibleParents.length) {
// NOTE: B254768 - reason of setTimeout method using.
window.setTimeout(() => {
nativeMethods.setTimeout.call(window, () => {
eventSimulator.blur(target);
}, 0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/core/request-barrier.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default class RequestBarrier extends EventEmitter {

var onRequestsFinished = () => {
if (this.watchdog)
window.clearTimeout(this.watchdog);
nativeMethods.clearTimeout.call(window, this.watchdog);

this._unbindHandlers();
resolve();
Expand Down
6 changes: 3 additions & 3 deletions src/client/core/utils/wait-for.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ export default function (fn, delay, timeout) {
result = fn();

if (result) {
window.clearInterval(intervalId);
window.clearTimeout(timeoutId);
nativeMethods.clearInterval.call(window, intervalId);
nativeMethods.clearTimeout.call(window, timeoutId);
resolve(result);
}
}, delay);

var timeoutId = nativeMethods.setTimeout.call(window, () => {
window.clearInterval(intervalId);
nativeMethods.clearInterval.call(window, intervalId);
reject();
}, timeout);
});
Expand Down
5 changes: 3 additions & 2 deletions src/client/ui/modal-background.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import hammerhead from './deps/hammerhead';
import testCafeCore from './deps/testcafe-core';

var shadowUI = hammerhead.shadowUI;
var shadowUI = hammerhead.shadowUI;
var nativeMethods = hammerhead.nativeMethods;

var eventUtils = testCafeCore.eventUtils;
var styleUtils = testCafeCore.styleUtils;
Expand Down Expand Up @@ -109,7 +110,7 @@ export function initAndShowLoadingText () {
if (document.body)
initAndShow();
else
window.setTimeout(tryShowBeforeReady, 0);
nativeMethods.setTimeout.call(window, tryShowBeforeReady, 0);
}
};

Expand Down
21 changes: 11 additions & 10 deletions src/client/ui/progress-panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import hammerhead from '../deps/hammerhead';
import testCafeCore from '../deps/testcafe-core';
import ProgressBar from './progress-bar';

var shadowUI = hammerhead.shadowUI;
var shadowUI = hammerhead.shadowUI;
var nativeMethods = hammerhead.nativeMethods;

var eventUtils = testCafeCore.eventUtils;
var styleUtils = testCafeCore.styleUtils;
Expand Down Expand Up @@ -84,7 +85,7 @@ export default class ProgressPanel {
}

_stopAnimation () {
window.clearInterval(this.animationInterval);
nativeMethods.clearInterval.call(window, this.animationInterval);
}

_animate (el, duration, show, complete) {
Expand All @@ -101,7 +102,7 @@ export default class ProgressPanel {

this._stopAnimation();

this.animationInterval = window.setInterval(() => {
this.animationInterval = nativeMethods.setInterval.call(window, () => {
passedTime = Date.now() - startTime;
progress = Math.min(passedTime / duration, 1);
delta = 0.5 - Math.cos(progress * Math.PI) / 2;
Expand Down Expand Up @@ -137,13 +138,13 @@ export default class ProgressPanel {
this.titleDiv.textContent = text;
this._setSuccess(false);

this.openingTimeout = window.setTimeout(() => {
this.openingTimeout = nativeMethods.setTimeout.call(window, () => {
this.openingTimeout = null;

this._setCurrentProgress();
this._showPanel();

this.updateInterval = window.setInterval(() => this._setCurrentProgress(), UPDATE_INTERVAL);
this.updateInterval = nativeMethods.setInterval.call(window, () => this._setCurrentProgress(), UPDATE_INTERVAL);
}, OPENING_DELAY);
}

Expand All @@ -152,23 +153,23 @@ export default class ProgressPanel {
this._setSuccess(true);

if (this.openingTimeout) {
window.clearTimeout(this.openingTimeout);
nativeMethods.clearTimeout.call(window, this.openingTimeout);
this.openingTimeout = null;
}

if (this.updateInterval) {
window.clearInterval(this.updateInterval);
nativeMethods.clearInterval.call(window, this.updateInterval);
this.updateInterval = null;
}

if (success) {
if (this.startTime && Date.now() - this.startTime < MIN_SHOWING_TIME) {
window.setTimeout(() => {
window.setTimeout(() => this._hidePanel(false), SHOWING_DELAY);
nativeMethods.setTimeout.call(window, () => {
nativeMethods.setTimeout.call(window, () => this._hidePanel(false), SHOWING_DELAY);
}, UPDATE_INTERVAL);
}
else
window.setTimeout(() => this._hidePanel(false), SHOWING_DELAY);
nativeMethods.setTimeout.call(window, () => this._hidePanel(false), SHOWING_DELAY);
}
else
this._hidePanel(true);
Expand Down
3 changes: 2 additions & 1 deletion src/client/ui/select-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import testCafeCore from './deps/testcafe-core';

var shadowUI = hammerhead.shadowUI;
var browserUtils = hammerhead.utils.browser;
var nativeMethods = hammerhead.nativeMethods;
var eventSimulator = hammerhead.eventSandbox.eventSimulator;

var positionUtils = testCafeCore.positionUtils;
Expand Down Expand Up @@ -144,7 +145,7 @@ export function expandOptionList (select) {

createChildren(selectChildren, optionList);

window.setTimeout(() => {
nativeMethods.setTimeout.call(window, () => {
eventUtils.bind(document, 'mousedown', onDocumentMouseDown);
}, 0);

Expand Down

0 comments on commit f4105dc

Please sign in to comment.