source: node_modules/recharts/es6/animation/timeoutController.js@ a762898

Last change on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Added visualizations

  • Property mode set to 100644
File size: 990 bytes
Line 
1/**
2 * Callback type for the timeout function.
3 * Receives current time in milliseconds as an argument.
4 */
5
6/**
7 * A function that, when called, cancels the timeout.
8 */
9
10export class RequestAnimationFrameTimeoutController {
11 setTimeout(callback) {
12 var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
13 var startTime = performance.now();
14 var requestId = null;
15 var executeCallback = now => {
16 if (now - startTime >= delay) {
17 callback(now);
18 // tests fail without the extra if, even when five lines below it's not needed
19 // TODO finish transition to the mocked timeout controller and then remove this condition
20 } else if (typeof requestAnimationFrame === 'function') {
21 requestId = requestAnimationFrame(executeCallback);
22 }
23 };
24 requestId = requestAnimationFrame(executeCallback);
25 return () => {
26 if (requestId != null) {
27 cancelAnimationFrame(requestId);
28 }
29 };
30 }
31}
Note: See TracBrowser for help on using the repository browser.