From 7f79b3180815c3e5b25aaa65f17e4b5a0f7ff81a Mon Sep 17 00:00:00 2001 From: Amr Labib Date: Sat, 17 Apr 2021 15:36:58 +0200 Subject: [PATCH] version 3.0.0 in package.json --- docs/index.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/index.js b/docs/index.js index 0b4cfff..aa56969 100644 --- a/docs/index.js +++ b/docs/index.js @@ -166,7 +166,7 @@ eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.default = UseTimerDemo;\n\nvar _react = __webpack_require__(/*! react */ \"./node_modules/react/index.js\");\n\nvar _react2 = _interopRequireDefault(_react);\n\nvar _index = __webpack_require__(/*! ../../src/index */ \"./src/index.js\");\n\nvar _TimerStyled = __webpack_require__(/*! ./TimerStyled */ \"./demo/components/TimerStyled.js\");\n\nvar _TimerStyled2 = _interopRequireDefault(_TimerStyled);\n\nvar _Button = __webpack_require__(/*! ./Button */ \"./demo/components/Button.js\");\n\nvar _Button2 = _interopRequireDefault(_Button);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction UseTimerDemo(_ref) {\n var expiryTimestamp = _ref.expiryTimestamp;\n\n var _useTimer = (0, _index.useTimer)({ expiryTimestamp: expiryTimestamp, autoStart: false, onExpire: function onExpire() {\n return console.warn('onExpire called');\n } }),\n seconds = _useTimer.seconds,\n minutes = _useTimer.minutes,\n hours = _useTimer.hours,\n days = _useTimer.days,\n start = _useTimer.start,\n pause = _useTimer.pause,\n resume = _useTimer.resume,\n restart = _useTimer.restart;\n\n return _react2.default.createElement(\n 'div',\n null,\n _react2.default.createElement(\n 'h2',\n null,\n 'UseTimer Demo'\n ),\n _react2.default.createElement(_TimerStyled2.default, { seconds: seconds, minutes: minutes, hours: hours, days: days }),\n _react2.default.createElement(\n _Button2.default,\n { type: 'button', onClick: start },\n 'Start'\n ),\n _react2.default.createElement(\n _Button2.default,\n { type: 'button', onClick: pause },\n 'Pause'\n ),\n _react2.default.createElement(\n _Button2.default,\n { type: 'button', onClick: resume },\n 'Resume'\n ),\n _react2.default.createElement(\n _Button2.default,\n {\n type: 'button',\n onClick: function onClick() {\n // Restarts to 10 minutes timer\n var time = new Date();\n time.setSeconds(time.getSeconds() + 600);\n restart(time);\n }\n },\n 'Restart'\n )\n );\n}\n\n//# sourceURL=webpack:///./demo/components/UseTimerDemo.js?"); +eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.default = UseTimerDemo;\n\nvar _react = __webpack_require__(/*! react */ \"./node_modules/react/index.js\");\n\nvar _react2 = _interopRequireDefault(_react);\n\nvar _index = __webpack_require__(/*! ../../src/index */ \"./src/index.js\");\n\nvar _TimerStyled = __webpack_require__(/*! ./TimerStyled */ \"./demo/components/TimerStyled.js\");\n\nvar _TimerStyled2 = _interopRequireDefault(_TimerStyled);\n\nvar _Button = __webpack_require__(/*! ./Button */ \"./demo/components/Button.js\");\n\nvar _Button2 = _interopRequireDefault(_Button);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction UseTimerDemo(_ref) {\n var expiryTimestamp = _ref.expiryTimestamp;\n\n var _useTimer = (0, _index.useTimer)({ expiryTimestamp: expiryTimestamp, autoStart: true, onExpire: function onExpire() {\n return console.warn('onExpire called');\n } }),\n seconds = _useTimer.seconds,\n minutes = _useTimer.minutes,\n hours = _useTimer.hours,\n days = _useTimer.days,\n start = _useTimer.start,\n pause = _useTimer.pause,\n resume = _useTimer.resume,\n restart = _useTimer.restart;\n\n return _react2.default.createElement(\n 'div',\n null,\n _react2.default.createElement(\n 'h2',\n null,\n 'UseTimer Demo'\n ),\n _react2.default.createElement(_TimerStyled2.default, { seconds: seconds, minutes: minutes, hours: hours, days: days }),\n _react2.default.createElement(\n _Button2.default,\n { type: 'button', onClick: start },\n 'Start'\n ),\n _react2.default.createElement(\n _Button2.default,\n { type: 'button', onClick: pause },\n 'Pause'\n ),\n _react2.default.createElement(\n _Button2.default,\n { type: 'button', onClick: resume },\n 'Resume'\n ),\n _react2.default.createElement(\n _Button2.default,\n {\n type: 'button',\n onClick: function onClick() {\n // Restarts to 10 minutes timer\n var time = new Date();\n time.setSeconds(time.getSeconds() + 600);\n restart(time);\n }\n },\n 'Restart'\n )\n );\n}\n\n//# sourceURL=webpack:///./demo/components/UseTimerDemo.js?"); /***/ }), @@ -511,7 +511,7 @@ eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nexports.default = useTimer;\n\nvar _react = __webpack_require__(/*! react */ \"./node_modules/react/index.js\");\n\nvar _utils = __webpack_require__(/*! ./utils */ \"./src/utils/index.js\");\n\nvar _hooks = __webpack_require__(/*! ./hooks */ \"./src/hooks/index.js\");\n\nfunction useTimer(_ref) {\n var expiry = _ref.expiryTimestamp,\n onExpire = _ref.onExpire,\n autoStart = _ref.autoStart;\n\n var _useState = (0, _react.useState)(expiry),\n _useState2 = _slicedToArray(_useState, 2),\n expiryTimestamp = _useState2[0],\n setExpiryTimestamp = _useState2[1];\n\n var _useState3 = (0, _react.useState)(_utils.Time.getSecondsFromExpiry(expiryTimestamp)),\n _useState4 = _slicedToArray(_useState3, 2),\n seconds = _useState4[0],\n setSeconds = _useState4[1];\n\n var _useState5 = (0, _react.useState)(autoStart),\n _useState6 = _slicedToArray(_useState5, 2),\n isRunning = _useState6[0],\n setIsRunning = _useState6[1];\n\n var _useState7 = (0, _react.useState)(autoStart),\n _useState8 = _slicedToArray(_useState7, 2),\n didStart = _useState8[0],\n setDidStart = _useState8[1];\n\n function handleExpire() {\n _utils.Validate.onExpire(onExpire) && onExpire();\n }\n\n function pause() {\n setIsRunning(false);\n }\n\n function resume() {\n var time = new Date();\n time.setSeconds(time.getSeconds() + seconds); // calculate new expiry timestamp based on last paused seconds count\n setExpiryTimestamp(time);\n setIsRunning(true);\n setSeconds(_utils.Time.getSecondsFromExpiry(time));\n }\n\n function start() {\n if (didStart) {\n setIsRunning(true);\n setSeconds(_utils.Time.getSecondsFromExpiry(expiryTimestamp));\n } else {\n resume();\n setDidStart(true);\n }\n }\n\n function restart(newExpiryTimestamp) {\n setDidStart(autoStart);\n setIsRunning(autoStart);\n setExpiryTimestamp(newExpiryTimestamp);\n setSeconds(_utils.Time.getSecondsFromExpiry(newExpiryTimestamp));\n }\n\n (0, _hooks.useInterval)(function () {\n var secondsValue = _utils.Time.getSecondsFromExpiry(expiryTimestamp);\n if (secondsValue <= 0) {\n handleExpire();\n }\n setSeconds(secondsValue);\n }, isRunning ? 1000 : null);\n\n return _extends({}, _utils.Time.getTimeFromSeconds(seconds), { start: start, pause: pause, resume: resume, restart: restart, isRunning: isRunning\n });\n}\n\n//# sourceURL=webpack:///./src/useTimer.js?"); +eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nexports.default = useTimer;\n\nvar _react = __webpack_require__(/*! react */ \"./node_modules/react/index.js\");\n\nvar _utils = __webpack_require__(/*! ./utils */ \"./src/utils/index.js\");\n\nvar _hooks = __webpack_require__(/*! ./hooks */ \"./src/hooks/index.js\");\n\nvar DEFAULT_DELAY = 1000;\nfunction useTimer(_ref) {\n var expiry = _ref.expiryTimestamp,\n onExpire = _ref.onExpire,\n autoStart = _ref.autoStart;\n\n var _useState = (0, _react.useState)(expiry),\n _useState2 = _slicedToArray(_useState, 2),\n expiryTimestamp = _useState2[0],\n setExpiryTimestamp = _useState2[1];\n\n var _useState3 = (0, _react.useState)(_utils.Time.getSecondsFromExpiry(expiryTimestamp)),\n _useState4 = _slicedToArray(_useState3, 2),\n seconds = _useState4[0],\n setSeconds = _useState4[1];\n\n var _useState5 = (0, _react.useState)(autoStart),\n _useState6 = _slicedToArray(_useState5, 2),\n isRunning = _useState6[0],\n setIsRunning = _useState6[1];\n\n var _useState7 = (0, _react.useState)(autoStart),\n _useState8 = _slicedToArray(_useState7, 2),\n didStart = _useState8[0],\n setDidStart = _useState8[1];\n\n var extraMilliSeconds = Math.floor((seconds - Math.floor(seconds)) * 1000);\n\n var _useState9 = (0, _react.useState)(extraMilliSeconds > 0 ? extraMilliSeconds : 1000),\n _useState10 = _slicedToArray(_useState9, 2),\n delay = _useState10[0],\n setDelay = _useState10[1];\n\n function handleExpire() {\n _utils.Validate.onExpire(onExpire) && onExpire();\n setIsRunning(false);\n setDelay(null);\n }\n\n function pause() {\n setIsRunning(false);\n }\n\n function restart(newExpiryTimestamp, newAutoStart) {\n var secondsValue = _utils.Time.getSecondsFromExpiry(newExpiryTimestamp);\n var extraMilliSecondsValue = Math.floor((secondsValue - Math.floor(secondsValue)) * 1000);\n setDelay(extraMilliSecondsValue > 0 ? extraMilliSecondsValue : 1000);\n setDidStart(newAutoStart);\n setIsRunning(newAutoStart);\n setExpiryTimestamp(newExpiryTimestamp);\n setSeconds(secondsValue);\n }\n\n function resume() {\n var time = new Date();\n time.setMilliseconds(time.getMilliseconds() + seconds * 1000);\n restart(time, true);\n }\n\n function start() {\n if (didStart) {\n setSeconds(_utils.Time.getSecondsFromExpiry(expiryTimestamp));\n setIsRunning(true);\n } else {\n resume();\n }\n }\n\n (0, _hooks.useInterval)(function () {\n if (delay !== DEFAULT_DELAY) {\n setDelay(DEFAULT_DELAY);\n }\n var secondsValue = _utils.Time.getSecondsFromExpiry(expiryTimestamp);\n setSeconds(secondsValue);\n if (secondsValue <= 0) {\n handleExpire();\n }\n }, isRunning ? delay : null);\n\n return _extends({}, _utils.Time.getTimeFromSeconds(seconds), { start: start, pause: pause, resume: resume, restart: restart, isRunning: isRunning\n });\n}\n\n//# sourceURL=webpack:///./src/useTimer.js?"); /***/ }), diff --git a/package.json b/package.json index 4283437..4d180bf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-timer-hook", - "version": "2.0.7", + "version": "3.0.0", "description": "React timer hook is a custom react hook built to handle timers(countdown), stopwatch and time logic/state in your react component.", "main": "dist/index.js", "types": "dist/index.d.ts",