use-elapsed-time
Advanced tools
Comparing version 2.1.2 to 2.1.3
# Change Log | ||
## 2.1.3 (May 29th, 2020) | ||
**Big fix:** | ||
- SSR: use `useEffect` when environment is `node` or `window` is undefined. When the environment is browser `useLayoutEffect` should be used instead | ||
- Remove side effects from `useState` so `React.StrictMode` doesn't bug the hook in development | ||
- Add a test to ensure that timeout is cancelled when `isPlaying` is set to `false` when the duration is reached | ||
## 2.1.2 (May 18th, 2020) | ||
**Big fix:** | ||
- Reset method will now ignore any none number value passed to it and it will use the previous `startAt` value | ||
## 2.1.1 (May 13th, 2020) | ||
@@ -4,0 +18,0 @@ |
@@ -1,1 +0,1 @@ | ||
module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var u=t[n]={i:n,l:!1,exports:{}};return e[n].call(u.exports,u,u.exports,r),u.l=!0,u.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var u in e)r.d(n,u,function(t){return e[t]}.bind(null,u));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=1)}([function(e,t){e.exports=require("react")},function(e,t,r){"use strict";r.r(t),r.d(t,"useElapsedTime",(function(){return c}));var n=r(0);function u(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var r=[],n=!0,u=!1,o=void 0;try{for(var c,i=e[Symbol.iterator]();!(n=(c=i.next()).done)&&(r.push(c.value),!t||r.length!==t);n=!0);}catch(e){u=!0,o=e}finally{try{n||null==i.return||i.return()}finally{if(u)throw o}}return r}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return o(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return o(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var c=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.duration,o=t.onComplete,c=t.startAt,i=void 0===c?0:c,a=t.autoResetKey,f=Object(n.useState)(i),l=u(f,2),s=l[0],b=l[1],y=Object(n.useRef)(-1e3*i),d=Object(n.useRef)(null),m=Object(n.useRef)(null),p=Object(n.useRef)(null),v=Object(n.useRef)(!0),j=Object(n.useRef)(!1),O=Object(n.useRef)(0),A=Object(n.useCallback)((function(e){O.current+=1,b("number"==typeof e?e:i)}),[]),g=function e(t){var n=t/1e3;if(null===m.current)return m.current=n,void(d.current=requestAnimationFrame(e));b((function(t){var u=t+(n-m.current);if("number"!=typeof r||u<r)return m.current=n,d.current=requestAnimationFrame(e),u;if(j.current=!0,"function"==typeof o){y.current+=1e3*r;var c=y.current/1e3,i=o(c)||{},a=i.shouldRepeat,f=void 0!==a&&a,l=i.delay,s=void 0===l?0:l,b=i.newStartAt;f&&(p.current=setTimeout((function(){A(b)}),1e3*s))}return r}))},S=function(){cancelAnimationFrame(d.current),clearTimeout(p.current),m.current=null};return Object(n.useLayoutEffect)((function(){return e&&(d.current=requestAnimationFrame(g)),S}),[e]),Object(n.useLayoutEffect)((function(){e&&!v.current&&(S(),d.current=requestAnimationFrame(g))}),[r]),Object(n.useLayoutEffect)((function(){v.current||A()}),[a]),Object(n.useLayoutEffect)((function(){e&&j.current&&(j.current=!1,S(),d.current=requestAnimationFrame(g))}),[O.current]),Object(n.useLayoutEffect)((function(){v.current=!1}),[]),{elapsedTime:s,reset:A}}}]); | ||
module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var u=t[n]={i:n,l:!1,exports:{}};return e[n].call(u.exports,u,u.exports,r),u.l=!0,u.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var u in e)r.d(n,u,function(t){return e[t]}.bind(null,u));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=1)}([function(e,t){e.exports=require("react")},function(e,t,r){"use strict";r.r(t),r.d(t,"useElapsedTime",(function(){return i}));var n=r(0);function u(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var r=[],n=!0,u=!1,o=void 0;try{for(var i,c=e[Symbol.iterator]();!(n=(i=c.next()).done)&&(r.push(i.value),!t||r.length!==t);n=!0);}catch(e){u=!0,o=e}finally{try{n||null==c.return||c.return()}finally{if(u)throw o}}return r}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return o(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return o(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var i=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.duration,o=t.onComplete,i=t.startAt,a=void 0===i?0:i,f=t.autoResetKey,l=Object(n.useState)(a),s=u(l,2),d=s[0],m=s[1],y=Object(n.useRef)(-1e3*a),b=Object(n.useRef)(null),p=Object(n.useRef)(null),v=Object(n.useRef)(null),j=Object(n.useRef)(!0),O=Object(n.useRef)(!1),A=Object(n.useRef)(0),g=Object(n.useCallback)((function(e){A.current+=1,m("number"==typeof e?e:a)}),[]),S=function e(t){var n=t/1e3;if(null===p.current)return p.current=n,void(b.current=requestAnimationFrame(e));var u=n-p.current;if(p.current=n,m((function(e){var t=e+u;return"number"!=typeof r||t<r?t:(O.current=!0,r)})),O.current){if("function"==typeof o){y.current+=1e3*r;var i=y.current/1e3,c=o(i)||{},a=c.shouldRepeat,f=void 0!==a&&a,l=c.delay,s=void 0===l?0:l,d=c.newStartAt;f&&(v.current=setTimeout((function(){g(d)}),1e3*s))}}else b.current=requestAnimationFrame(e)},h=function(){cancelAnimationFrame(b.current),clearTimeout(v.current),p.current=null};return c((function(){return e&&(b.current=requestAnimationFrame(S)),h}),[e]),c((function(){e&&!j.current&&(h(),b.current=requestAnimationFrame(S))}),[r]),c((function(){j.current||g()}),[f]),c((function(){e&&O.current&&(O.current=!1,h(),b.current=requestAnimationFrame(S))}),[A.current]),c((function(){j.current=!1}),[]),{elapsedTime:d,reset:g}},c="undefined"==typeof window?n.useEffect:n.useLayoutEffect}]); |
{ | ||
"name": "use-elapsed-time", | ||
"version": "2.1.2", | ||
"version": "2.1.3", | ||
"description": "React hook to measure elapsed time using requestAnimationFrame", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15172