Skip to content

Commit

Permalink
v2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Albert González committed Aug 29, 2023
1 parent ca99edb commit c7c760b
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 67 deletions.
92 changes: 46 additions & 46 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* easytimer-react-hook
* Generated: 2022-08-24
* Version: 2.0.2
* Generated: 2023-08-29
* Version: 2.1.0
*/

(function (global, factory) {
Expand All @@ -10,52 +10,52 @@
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["easytimer-react-hook"] = {}, global.React, global.easytimer));
})(this, (function (exports, react, easytimer_js) { 'use strict';

var useTimer = function (_a) {
var _b = _a === void 0 ? {} : _a, startValues = _b.startValues, target = _b.target, precision = _b.precision, countdown = _b.countdown, updateWhenTargetAchieved = _b.updateWhenTargetAchieved;
var unitsToSave = ['days', 'hours', 'minutes', 'seconds', 'secondTenths'];
var updateCallback = function (timer) {
setTimerValues(timer.getTimeValues().toString(unitsToSave));
};
var onStarted = function (e) {
updateCallback(e.detail.timer);
setIsTargetAchieved(false);
};
var onTargetAchieved = function () { return setIsTargetAchieved(true); };
var addListeners = function () {
timer.on('started', onStarted);
timer.on('reset', onStarted);
if (updateWhenTargetAchieved) {
timer.on('targetAchieved', onTargetAchieved);
}
};
var removeListeners = function () {
timer.off('started', onStarted);
timer.off('reset', onStarted);
timer.off('targetAchieved', onTargetAchieved);
};
var timer = react.useState(new easytimer_js.Timer({
startValues: startValues,
target: target,
precision: precision,
countdown: countdown,
callback: updateCallback,
}))[0];
var _c = react.useState(timer.getTimeValues().toString(unitsToSave)), setTimerValues = _c[1];
var _d = react.useState(false), isTargetAchieved = _d[0], setIsTargetAchieved = _d[1];
react.useEffect(function () {
addListeners();
return function () { return removeListeners(); };
}, [updateWhenTargetAchieved]);
react.useEffect(function () {
return function () {
timer.stop();
removeListeners();
};
}, []);
return [timer, isTargetAchieved];
var useTimer = function (_a) {
var _b = _a === void 0 ? {} : _a, startValues = _b.startValues, target = _b.target, precision = _b.precision, countdown = _b.countdown, updateWhenTargetAchieved = _b.updateWhenTargetAchieved;
var unitsToSave = ['days', 'hours', 'minutes', 'seconds', 'secondTenths'];
var updateCallback = function (timer) {
setTimerValues(timer.getTimeValues().toString(unitsToSave));
};
var onStarted = function (e) {
updateCallback(e.detail.timer);
setIsTargetAchieved(false);
};
var onTargetAchieved = function () { return setIsTargetAchieved(true); };
var addListeners = function () {
timer.on('started', onStarted);
timer.on('reset', onStarted);
if (updateWhenTargetAchieved) {
timer.on('targetAchieved', onTargetAchieved);
}
};
var removeListeners = function () {
timer.off('started', onStarted);
timer.off('reset', onStarted);
timer.off('targetAchieved', onTargetAchieved);
};
var timer = react.useState(new easytimer_js.Timer({
startValues: startValues,
target: target,
precision: precision,
countdown: countdown,
callback: updateCallback,
}))[0];
var _c = react.useState(timer.getTimeValues().toString(unitsToSave)), setTimerValues = _c[1];
var _d = react.useState(false), isTargetAchieved = _d[0], setIsTargetAchieved = _d[1];
react.useEffect(function () {
addListeners();
return function () { return removeListeners(); };
}, [updateWhenTargetAchieved]);
react.useEffect(function () {
return function () {
timer.stop();
removeListeners();
};
}, []);
return [timer, isTargetAchieved];
};

exports["default"] = useTimer;
exports.default = useTimer;

Object.defineProperty(exports, '__esModule', { value: true });

Expand Down
4 changes: 2 additions & 2 deletions dist/index.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions dist/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Precision, Timer, TimerValues } from 'easytimer.js';
interface TimerHookConfig {
startValues?: TimerValues;
target?: TimerValues;
precision?: Precision;
countdown?: boolean;
updateWhenTargetAchieved?: boolean;
}
declare type TimerHookReturn = [Timer, boolean];
declare const useTimer: ({ startValues, target, precision, countdown, updateWhenTargetAchieved, }?: TimerHookConfig) => TimerHookReturn;
export default useTimer;
import { Precision, Timer, TimerValues } from 'easytimer.js';
interface TimerHookConfig {
startValues?: TimerValues;
target?: TimerValues;
precision?: Precision;
countdown?: boolean;
updateWhenTargetAchieved?: boolean;
}
type TimerHookReturn = [Timer, boolean];
declare const useTimer: ({ startValues, target, precision, countdown, updateWhenTargetAchieved, }?: TimerHookConfig) => TimerHookReturn;
export default useTimer;
2 changes: 1 addition & 1 deletion example/dist/index.css

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions example/dist/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "easytimer-react-hook",
"version": "2.0.2",
"version": "2.1.0",
"description": "React Hook that creates a timer using EasyTimer lib",
"main": "dist/index.min.js",
"types": "dist/src/index.d.ts",
Expand Down

0 comments on commit c7c760b

Please sign in to comment.