source: imaps-frontend/node_modules/react-use/lib/useRaf.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.3 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4var react_1 = require("react");
5var useIsomorphicLayoutEffect_1 = tslib_1.__importDefault(require("./useIsomorphicLayoutEffect"));
6var useRaf = function (ms, delay) {
7 if (ms === void 0) { ms = 1e12; }
8 if (delay === void 0) { delay = 0; }
9 var _a = react_1.useState(0), elapsed = _a[0], set = _a[1];
10 useIsomorphicLayoutEffect_1.default(function () {
11 var raf;
12 var timerStop;
13 var start;
14 var onFrame = function () {
15 var time = Math.min(1, (Date.now() - start) / ms);
16 set(time);
17 loop();
18 };
19 var loop = function () {
20 raf = requestAnimationFrame(onFrame);
21 };
22 var onStart = function () {
23 timerStop = setTimeout(function () {
24 cancelAnimationFrame(raf);
25 set(1);
26 }, ms);
27 start = Date.now();
28 loop();
29 };
30 var timerDelay = setTimeout(onStart, delay);
31 return function () {
32 clearTimeout(timerStop);
33 clearTimeout(timerDelay);
34 cancelAnimationFrame(raf);
35 };
36 }, [ms, delay]);
37 return elapsed;
38};
39exports.default = useRaf;
Note: See TracBrowser for help on using the repository browser.