|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
1.2 KB
|
| Line | |
|---|
| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.RequestAnimationFrameTimeoutController = void 0;
|
|---|
| 7 | /**
|
|---|
| 8 | * Callback type for the timeout function.
|
|---|
| 9 | * Receives current time in milliseconds as an argument.
|
|---|
| 10 | */
|
|---|
| 11 |
|
|---|
| 12 | /**
|
|---|
| 13 | * A function that, when called, cancels the timeout.
|
|---|
| 14 | */
|
|---|
| 15 |
|
|---|
| 16 | class RequestAnimationFrameTimeoutController {
|
|---|
| 17 | setTimeout(callback) {
|
|---|
| 18 | var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|---|
| 19 | var startTime = performance.now();
|
|---|
| 20 | var requestId = null;
|
|---|
| 21 | var executeCallback = now => {
|
|---|
| 22 | if (now - startTime >= delay) {
|
|---|
| 23 | callback(now);
|
|---|
| 24 | // tests fail without the extra if, even when five lines below it's not needed
|
|---|
| 25 | // TODO finish transition to the mocked timeout controller and then remove this condition
|
|---|
| 26 | } else if (typeof requestAnimationFrame === 'function') {
|
|---|
| 27 | requestId = requestAnimationFrame(executeCallback);
|
|---|
| 28 | }
|
|---|
| 29 | };
|
|---|
| 30 | requestId = requestAnimationFrame(executeCallback);
|
|---|
| 31 | return () => {
|
|---|
| 32 | if (requestId != null) {
|
|---|
| 33 | cancelAnimationFrame(requestId);
|
|---|
| 34 | }
|
|---|
| 35 | };
|
|---|
| 36 | }
|
|---|
| 37 | }
|
|---|
| 38 | exports.RequestAnimationFrameTimeoutController = RequestAnimationFrameTimeoutController; |
|---|
Note:
See
TracBrowser
for help on using the repository browser.