react-interval
Version:
Safe React wrapper for setInterval
1 lines • 4.1 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("React")):"function"==typeof define&&define.amd?define(["React"],e):"object"==typeof exports?exports.ReactInterval=e(require("React")):t.ReactInterval=e(t.React)}(window,(function(t){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=1)}([function(e,n){e.exports=t},function(t,e,n){var r=n(2).ReactInterval;r.ReactInterval=r,t.exports=r},function(t,e,n){"use strict";n.r(e),n.d(e,"ReactInterval",(function(){return y}));var r=n(0);function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function u(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function c(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function i(t,e){return(i=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function a(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=p(t);if(e){var o=p(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return f(this,n)}}function f(t,e){return!e||"object"!==o(e)&&"function"!=typeof e?l(t):e}function l(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function p(t){return(p=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function s(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var y=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&i(t,e)}(f,t);var e,n,r,o=a(f);function f(){var t;u(this,f);for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return s(l(t=o.call.apply(o,[this].concat(n))),"callback",(function(){t.timer&&((0,t.props.callback)(),t.start())})),s(l(t),"start",(function(){t.stop();var e=t.props.timeout;t.timer=setTimeout(t.callback,e)})),s(l(t),"stop",(function(){clearTimeout(t.timer),t.timer=null})),s(l(t),"render",(function(){return!1})),t}return e=f,(n=[{key:"componentDidMount",value:function(){this.props.enabled&&this.start()}},{key:"shouldComponentUpdate",value:function(t){var e=t.timeout,n=t.callback,r=t.enabled,o=this.props,u=o.timeout,c=o.callback,i=o.enabled;return u!==e||c!==n||i!==r}},{key:"componentDidUpdate",value:function(t){var e=t.enabled,n=t.timeout,r=this.props,o=r.timeout,u=r.enabled;u===e&&o===n||(u?this.start():this.stop())}},{key:"componentWillUnmount",value:function(){this.stop()}}])&&c(e.prototype,n),r&&c(e,r),f}(n.n(r).a.Component);s(y,"defaultProps",{enabled:!1,timeout:1e3})}])}));