|
1 | 1 | /**
|
2 | 2 | * easytimer-react-hook
|
3 |
| - * Generated: 2022-08-24 |
4 |
| - * Version: 2.0.2 |
| 3 | + * Generated: 2023-08-29 |
| 4 | + * Version: 2.1.0 |
5 | 5 | */
|
6 | 6 |
|
7 | 7 | (function (global, factory) {
|
|
10 | 10 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["easytimer-react-hook"] = {}, global.React, global.easytimer));
|
11 | 11 | })(this, (function (exports, react, easytimer_js) { 'use strict';
|
12 | 12 |
|
13 |
| - var useTimer = function (_a) { |
14 |
| - var _b = _a === void 0 ? {} : _a, startValues = _b.startValues, target = _b.target, precision = _b.precision, countdown = _b.countdown, updateWhenTargetAchieved = _b.updateWhenTargetAchieved; |
15 |
| - var unitsToSave = ['days', 'hours', 'minutes', 'seconds', 'secondTenths']; |
16 |
| - var updateCallback = function (timer) { |
17 |
| - setTimerValues(timer.getTimeValues().toString(unitsToSave)); |
18 |
| - }; |
19 |
| - var onStarted = function (e) { |
20 |
| - updateCallback(e.detail.timer); |
21 |
| - setIsTargetAchieved(false); |
22 |
| - }; |
23 |
| - var onTargetAchieved = function () { return setIsTargetAchieved(true); }; |
24 |
| - var addListeners = function () { |
25 |
| - timer.on('started', onStarted); |
26 |
| - timer.on('reset', onStarted); |
27 |
| - if (updateWhenTargetAchieved) { |
28 |
| - timer.on('targetAchieved', onTargetAchieved); |
29 |
| - } |
30 |
| - }; |
31 |
| - var removeListeners = function () { |
32 |
| - timer.off('started', onStarted); |
33 |
| - timer.off('reset', onStarted); |
34 |
| - timer.off('targetAchieved', onTargetAchieved); |
35 |
| - }; |
36 |
| - var timer = react.useState(new easytimer_js.Timer({ |
37 |
| - startValues: startValues, |
38 |
| - target: target, |
39 |
| - precision: precision, |
40 |
| - countdown: countdown, |
41 |
| - callback: updateCallback, |
42 |
| - }))[0]; |
43 |
| - var _c = react.useState(timer.getTimeValues().toString(unitsToSave)), setTimerValues = _c[1]; |
44 |
| - var _d = react.useState(false), isTargetAchieved = _d[0], setIsTargetAchieved = _d[1]; |
45 |
| - react.useEffect(function () { |
46 |
| - addListeners(); |
47 |
| - return function () { return removeListeners(); }; |
48 |
| - }, [updateWhenTargetAchieved]); |
49 |
| - react.useEffect(function () { |
50 |
| - return function () { |
51 |
| - timer.stop(); |
52 |
| - removeListeners(); |
53 |
| - }; |
54 |
| - }, []); |
55 |
| - return [timer, isTargetAchieved]; |
| 13 | + var useTimer = function (_a) { |
| 14 | + var _b = _a === void 0 ? {} : _a, startValues = _b.startValues, target = _b.target, precision = _b.precision, countdown = _b.countdown, updateWhenTargetAchieved = _b.updateWhenTargetAchieved; |
| 15 | + var unitsToSave = ['days', 'hours', 'minutes', 'seconds', 'secondTenths']; |
| 16 | + var updateCallback = function (timer) { |
| 17 | + setTimerValues(timer.getTimeValues().toString(unitsToSave)); |
| 18 | + }; |
| 19 | + var onStarted = function (e) { |
| 20 | + updateCallback(e.detail.timer); |
| 21 | + setIsTargetAchieved(false); |
| 22 | + }; |
| 23 | + var onTargetAchieved = function () { return setIsTargetAchieved(true); }; |
| 24 | + var addListeners = function () { |
| 25 | + timer.on('started', onStarted); |
| 26 | + timer.on('reset', onStarted); |
| 27 | + if (updateWhenTargetAchieved) { |
| 28 | + timer.on('targetAchieved', onTargetAchieved); |
| 29 | + } |
| 30 | + }; |
| 31 | + var removeListeners = function () { |
| 32 | + timer.off('started', onStarted); |
| 33 | + timer.off('reset', onStarted); |
| 34 | + timer.off('targetAchieved', onTargetAchieved); |
| 35 | + }; |
| 36 | + var timer = react.useState(new easytimer_js.Timer({ |
| 37 | + startValues: startValues, |
| 38 | + target: target, |
| 39 | + precision: precision, |
| 40 | + countdown: countdown, |
| 41 | + callback: updateCallback, |
| 42 | + }))[0]; |
| 43 | + var _c = react.useState(timer.getTimeValues().toString(unitsToSave)), setTimerValues = _c[1]; |
| 44 | + var _d = react.useState(false), isTargetAchieved = _d[0], setIsTargetAchieved = _d[1]; |
| 45 | + react.useEffect(function () { |
| 46 | + addListeners(); |
| 47 | + return function () { return removeListeners(); }; |
| 48 | + }, [updateWhenTargetAchieved]); |
| 49 | + react.useEffect(function () { |
| 50 | + return function () { |
| 51 | + timer.stop(); |
| 52 | + removeListeners(); |
| 53 | + }; |
| 54 | + }, []); |
| 55 | + return [timer, isTargetAchieved]; |
56 | 56 | };
|
57 | 57 |
|
58 |
| - exports["default"] = useTimer; |
| 58 | + exports.default = useTimer; |
59 | 59 |
|
60 | 60 | Object.defineProperty(exports, '__esModule', { value: true });
|
61 | 61 |
|
|
0 commit comments