react-idle-timer
Advanced tools
Comparing version
@@ -0,1 +1,4 @@ | ||
### 4.2.2 | ||
- Fixes an issue updating state from inside onIdle (see #71) | ||
### 4.2.1 | ||
@@ -2,0 +5,0 @@ |
@@ -1,2 +0,2 @@ | ||
import{Component}from"react";import PropTypes from"prop-types";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),inherits=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},possibleConstructorReturn=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},IS_BROWSER="object"===("undefined"==typeof window?"undefined":"undefined"==typeof window?"undefined":_typeof(window)),DEFAULT_ELEMENT=IS_BROWSER?document:{},DEFAULT_EVENTS=["mousemove","keydown","wheel","DOMMouseScroll","mouseWheel","mousedown","touchstart","touchmove","MSPointerDown","MSPointerMove"],IdleTimer=function(e){function t(e){classCallCheck(this,t);var n=possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));if(n.state={idle:!1,oldDate:+new Date,lastActive:+new Date,remaining:null,pageX:null,pageY:null},n.tId=null,n._handleEvent=function(e){var t=n.state,o=t.remaining,i=t.pageX,r=t.pageY,s=t.idle,u=n.props,a=u.timeout,l=u.onAction,p=u.debounce,c=u.throttle,d=u.stopOnIdle;if(p>0?n.debouncedAction(e):c>0?n.throttledAction(e):l(e),!o){if("mousemove"===e.type){if(e.pageX===i&&e.pageY===r)return;if(void 0===e.pageX&&void 0===e.pageY)return;if(n.getElapsedTime()<200)return}clearTimeout(n.tId),n.tId=null,s&&!d&&n.toggleIdleState(e),n.setState({lastActive:+new Date,pageX:e.pageX,pageY:e.pageY}),s&&d||(n.tId=setTimeout(n.toggleIdleState,a))}},e.debounce>0&&e.throttle>0)throw new Error("onAction can either be throttled or debounced (not both)");return e.debounce>0&&(n.debouncedAction=debounced(e.onAction,e.debounce)),e.throttle>0&&(n.throttledAction=throttled(e.onAction,e.throttle)),e.startOnMount||(n.state.idle=!0),n.toggleIdleState=n._toggleIdleState.bind(n),n.reset=n._reset.bind(n),n.pause=n._pause.bind(n),n.resume=n._resume.bind(n),n.getRemainingTime=n._getRemainingTime.bind(n),n.getElapsedTime=n._getElapsedTime.bind(n),n.getLastActiveTime=n._getLastActiveTime.bind(n),n.isIdle=n._isIdle.bind(n),n}return inherits(t,Component),createClass(t,[{key:"componentWillMount",value:function(){this._bindEvents()}},{key:"componentDidMount",value:function(){this.props.startOnMount&&this.reset()}},{key:"componentWillUnmount",value:function(){clearTimeout(this.tId),this._unbindEvents()}},{key:"render",value:function(){return this.props.children||null}},{key:"_bindEvents",value:function(){var e=this;if(IS_BROWSER){var t=this.state.eventsBound,n=this.props,o=n.element,i=n.events,r=n.passive,s=n.capture;t||(i.forEach(function(t){o.addEventListener(t,e._handleEvent,{capture:s,passive:r})}),this.setState({eventsBound:!0}))}}},{key:"_unbindEvents",value:function(){var e=this;if(IS_BROWSER){var t=this.props,n=t.element,o=t.events,i=t.passive,r=t.capture;this.state.eventsBound&&(o.forEach(function(t){n.removeEventListener(t,e._handleEvent,{capture:r,passive:i})}),this.setState({eventsBound:!1}))}}},{key:"_toggleIdleState",value:function(e){var t=this.state.idle,n=this.props,o=n.onActive,i=n.onIdle,r=n.stopOnIdle;t?r||(this._bindEvents(),o(e)):(r&&(clearTimeout(this.tId),this.tId=null,this._unbindEvents()),i(e)),this.setState({idle:!t})}},{key:"_reset",value:function(){clearTimeout(this.tId),this.tId=null,this._bindEvents(),this.setState({idle:!1,oldDate:+new Date,lastActive:this.state.oldDate,remaining:null});var e=this.props.timeout;this.tId=setTimeout(this.toggleIdleState,e)}},{key:"_pause",value:function(){null===this.state.remaining&&(this._unbindEvents(),clearTimeout(this.tId),this.tId=null,this.setState({remaining:this.getRemainingTime()}))}},{key:"_resume",value:function(){var e=this.state,t=e.remaining,n=e.idle;null!==t&&(this._bindEvents(),n||(this.setState({remaining:null}),this.tId=setTimeout(this.toggleIdleState,t)))}},{key:"_getRemainingTime",value:function(){var e=this.state,t=e.remaining,n=e.idle,o=e.lastActive;if(n)return 0;if(null!==t)return t;var i=this.props.timeout-(+new Date-o);return i<0&&(i=0),i}},{key:"_getElapsedTime",value:function(){var e=this.state.oldDate;return+new Date-e}},{key:"_getLastActiveTime",value:function(){return this.state.lastActive}},{key:"_isIdle",value:function(){return this.state.idle}}]),t}();function debounced(e,t){var n=void 0;return function(){for(var o=arguments.length,i=Array(o),r=0;r<o;r++)i[r]=arguments[r];n&&clearTimeout(n),n=setTimeout(function(){e.apply(void 0,i),n=null},t)}}function throttled(e,t){var n=0;return function(){var o=(new Date).getTime();if(!(o-n<t))return n=o,e.apply(void 0,arguments)}}IdleTimer.propTypes={timeout:PropTypes.number,events:PropTypes.arrayOf(PropTypes.string),onIdle:PropTypes.func,onActive:PropTypes.func,onAction:PropTypes.func,debounce:PropTypes.number,throttle:PropTypes.number,element:PropTypes.oneOfType([PropTypes.object,PropTypes.element]),startOnMount:PropTypes.bool,stopOnIdle:PropTypes.bool,passive:PropTypes.bool,capture:PropTypes.bool},IdleTimer.defaultProps={timeout:12e5,element:DEFAULT_ELEMENT,events:DEFAULT_EVENTS,onIdle:function(){},onActive:function(){},onAction:function(){},debounce:0,throttle:0,startOnMount:!0,stopOnIdle:!1,capture:!0,passive:!0};export default IdleTimer; | ||
import{Component}from"react";import PropTypes from"prop-types";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),inherits=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},possibleConstructorReturn=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},IS_BROWSER="object"===("undefined"==typeof window?"undefined":"undefined"==typeof window?"undefined":_typeof(window)),DEFAULT_ELEMENT=IS_BROWSER?document:{},DEFAULT_EVENTS=["mousemove","keydown","wheel","DOMMouseScroll","mouseWheel","mousedown","touchstart","touchmove","MSPointerDown","MSPointerMove"],IdleTimer=function(e){function t(e){classCallCheck(this,t);var n=possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));if(n.state={idle:!1,oldDate:+new Date,lastActive:+new Date,remaining:null,pageX:null,pageY:null},n.tId=null,n._handleEvent=function(e){var t=n.state,o=t.remaining,i=t.pageX,r=t.pageY,s=t.idle,u=n.props,a=u.timeout,l=u.onAction,p=u.debounce,c=u.throttle,d=u.stopOnIdle;if(p>0?n.debouncedAction(e):c>0?n.throttledAction(e):l(e),!o){if("mousemove"===e.type){if(e.pageX===i&&e.pageY===r)return;if(void 0===e.pageX&&void 0===e.pageY)return;if(n.getElapsedTime()<200)return}clearTimeout(n.tId),n.tId=null,s&&!d&&n.toggleIdleState(e),n.setState({lastActive:+new Date,pageX:e.pageX,pageY:e.pageY}),s&&d||(n.tId=setTimeout(n.toggleIdleState,a))}},e.debounce>0&&e.throttle>0)throw new Error("onAction can either be throttled or debounced (not both)");return e.debounce>0&&(n.debouncedAction=debounced(e.onAction,e.debounce)),e.throttle>0&&(n.throttledAction=throttled(e.onAction,e.throttle)),e.startOnMount||(n.state.idle=!0),n.toggleIdleState=n._toggleIdleState.bind(n),n.reset=n._reset.bind(n),n.pause=n._pause.bind(n),n.resume=n._resume.bind(n),n.getRemainingTime=n._getRemainingTime.bind(n),n.getElapsedTime=n._getElapsedTime.bind(n),n.getLastActiveTime=n._getLastActiveTime.bind(n),n.isIdle=n._isIdle.bind(n),n}return inherits(t,Component),createClass(t,[{key:"componentWillMount",value:function(){this._bindEvents()}},{key:"componentDidMount",value:function(){this.props.startOnMount&&this.reset()}},{key:"componentWillUnmount",value:function(){clearTimeout(this.tId),this._unbindEvents()}},{key:"render",value:function(){return this.props.children||null}},{key:"_bindEvents",value:function(){var e=this;if(IS_BROWSER){var t=this.state.eventsBound,n=this.props,o=n.element,i=n.events,r=n.passive,s=n.capture;t||(i.forEach(function(t){o.addEventListener(t,e._handleEvent,{capture:s,passive:r})}),this.setState({eventsBound:!0}))}}},{key:"_unbindEvents",value:function(){var e=this;if(IS_BROWSER){var t=this.props,n=t.element,o=t.events,i=t.passive,r=t.capture;this.state.eventsBound&&(o.forEach(function(t){n.removeEventListener(t,e._handleEvent,{capture:r,passive:i})}),this.setState({eventsBound:!1}))}}},{key:"_toggleIdleState",value:function(e){var t=this,n=this.state.idle,o=this.props,i=o.onActive,r=o.onIdle,s=o.stopOnIdle;this.setState({idle:!n},function(){n?s||(t._bindEvents(),i(e)):(s&&(clearTimeout(t.tId),t.tId=null,t._unbindEvents()),r(e))})}},{key:"_reset",value:function(){clearTimeout(this.tId),this.tId=null,this._bindEvents(),this.setState({idle:!1,oldDate:+new Date,lastActive:this.state.oldDate,remaining:null});var e=this.props.timeout;this.tId=setTimeout(this.toggleIdleState,e)}},{key:"_pause",value:function(){null===this.state.remaining&&(this._unbindEvents(),clearTimeout(this.tId),this.tId=null,this.setState({remaining:this.getRemainingTime()}))}},{key:"_resume",value:function(){var e=this.state,t=e.remaining,n=e.idle;null!==t&&(this._bindEvents(),n||(this.setState({remaining:null}),this.tId=setTimeout(this.toggleIdleState,t)))}},{key:"_getRemainingTime",value:function(){var e=this.state,t=e.remaining,n=e.idle,o=e.lastActive;if(n)return 0;if(null!==t)return t;var i=this.props.timeout-(+new Date-o);return i<0&&(i=0),i}},{key:"_getElapsedTime",value:function(){var e=this.state.oldDate;return+new Date-e}},{key:"_getLastActiveTime",value:function(){return this.state.lastActive}},{key:"_isIdle",value:function(){return this.state.idle}}]),t}();function debounced(e,t){var n=void 0;return function(){for(var o=arguments.length,i=Array(o),r=0;r<o;r++)i[r]=arguments[r];n&&clearTimeout(n),n=setTimeout(function(){e.apply(void 0,i),n=null},t)}}function throttled(e,t){var n=0;return function(){var o=(new Date).getTime();if(!(o-n<t))return n=o,e.apply(void 0,arguments)}}IdleTimer.propTypes={timeout:PropTypes.number,events:PropTypes.arrayOf(PropTypes.string),onIdle:PropTypes.func,onActive:PropTypes.func,onAction:PropTypes.func,debounce:PropTypes.number,throttle:PropTypes.number,element:PropTypes.oneOfType([PropTypes.object,PropTypes.element]),startOnMount:PropTypes.bool,stopOnIdle:PropTypes.bool,passive:PropTypes.bool,capture:PropTypes.bool},IdleTimer.defaultProps={timeout:12e5,element:DEFAULT_ELEMENT,events:DEFAULT_EVENTS,onIdle:function(){},onActive:function(){},onAction:function(){},debounce:0,throttle:0,startOnMount:!0,stopOnIdle:!1,capture:!0,passive:!0};export default IdleTimer; | ||
//# sourceMappingURL=index.es.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var react=require("react"),PropTypes=_interopDefault(require("prop-types")),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),inherits=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},possibleConstructorReturn=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},IS_BROWSER="object"===("undefined"==typeof window?"undefined":"undefined"==typeof window?"undefined":_typeof(window)),DEFAULT_ELEMENT=IS_BROWSER?document:{},DEFAULT_EVENTS=["mousemove","keydown","wheel","DOMMouseScroll","mouseWheel","mousedown","touchstart","touchmove","MSPointerDown","MSPointerMove"],IdleTimer=function(e){function t(e){classCallCheck(this,t);var n=possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));if(n.state={idle:!1,oldDate:+new Date,lastActive:+new Date,remaining:null,pageX:null,pageY:null},n.tId=null,n._handleEvent=function(e){var t=n.state,o=t.remaining,i=t.pageX,r=t.pageY,s=t.idle,u=n.props,a=u.timeout,l=u.onAction,p=u.debounce,c=u.throttle,d=u.stopOnIdle;if(p>0?n.debouncedAction(e):c>0?n.throttledAction(e):l(e),!o){if("mousemove"===e.type){if(e.pageX===i&&e.pageY===r)return;if(void 0===e.pageX&&void 0===e.pageY)return;if(n.getElapsedTime()<200)return}clearTimeout(n.tId),n.tId=null,s&&!d&&n.toggleIdleState(e),n.setState({lastActive:+new Date,pageX:e.pageX,pageY:e.pageY}),s&&d||(n.tId=setTimeout(n.toggleIdleState,a))}},e.debounce>0&&e.throttle>0)throw new Error("onAction can either be throttled or debounced (not both)");return e.debounce>0&&(n.debouncedAction=debounced(e.onAction,e.debounce)),e.throttle>0&&(n.throttledAction=throttled(e.onAction,e.throttle)),e.startOnMount||(n.state.idle=!0),n.toggleIdleState=n._toggleIdleState.bind(n),n.reset=n._reset.bind(n),n.pause=n._pause.bind(n),n.resume=n._resume.bind(n),n.getRemainingTime=n._getRemainingTime.bind(n),n.getElapsedTime=n._getElapsedTime.bind(n),n.getLastActiveTime=n._getLastActiveTime.bind(n),n.isIdle=n._isIdle.bind(n),n}return inherits(t,e),createClass(t,[{key:"componentWillMount",value:function(){this._bindEvents()}},{key:"componentDidMount",value:function(){this.props.startOnMount&&this.reset()}},{key:"componentWillUnmount",value:function(){clearTimeout(this.tId),this._unbindEvents()}},{key:"render",value:function(){return this.props.children||null}},{key:"_bindEvents",value:function(){var e=this;if(IS_BROWSER){var t=this.state.eventsBound,n=this.props,o=n.element,i=n.events,r=n.passive,s=n.capture;t||(i.forEach(function(t){o.addEventListener(t,e._handleEvent,{capture:s,passive:r})}),this.setState({eventsBound:!0}))}}},{key:"_unbindEvents",value:function(){var e=this;if(IS_BROWSER){var t=this.props,n=t.element,o=t.events,i=t.passive,r=t.capture;this.state.eventsBound&&(o.forEach(function(t){n.removeEventListener(t,e._handleEvent,{capture:r,passive:i})}),this.setState({eventsBound:!1}))}}},{key:"_toggleIdleState",value:function(e){var t=this.state.idle,n=this.props,o=n.onActive,i=n.onIdle,r=n.stopOnIdle;t?r||(this._bindEvents(),o(e)):(r&&(clearTimeout(this.tId),this.tId=null,this._unbindEvents()),i(e)),this.setState({idle:!t})}},{key:"_reset",value:function(){clearTimeout(this.tId),this.tId=null,this._bindEvents(),this.setState({idle:!1,oldDate:+new Date,lastActive:this.state.oldDate,remaining:null});var e=this.props.timeout;this.tId=setTimeout(this.toggleIdleState,e)}},{key:"_pause",value:function(){null===this.state.remaining&&(this._unbindEvents(),clearTimeout(this.tId),this.tId=null,this.setState({remaining:this.getRemainingTime()}))}},{key:"_resume",value:function(){var e=this.state,t=e.remaining,n=e.idle;null!==t&&(this._bindEvents(),n||(this.setState({remaining:null}),this.tId=setTimeout(this.toggleIdleState,t)))}},{key:"_getRemainingTime",value:function(){var e=this.state,t=e.remaining,n=e.idle,o=e.lastActive;if(n)return 0;if(null!==t)return t;var i=this.props.timeout-(+new Date-o);return i<0&&(i=0),i}},{key:"_getElapsedTime",value:function(){var e=this.state.oldDate;return+new Date-e}},{key:"_getLastActiveTime",value:function(){return this.state.lastActive}},{key:"_isIdle",value:function(){return this.state.idle}}]),t}(react.Component);function debounced(e,t){var n=void 0;return function(){for(var o=arguments.length,i=Array(o),r=0;r<o;r++)i[r]=arguments[r];n&&clearTimeout(n),n=setTimeout(function(){e.apply(void 0,i),n=null},t)}}function throttled(e,t){var n=0;return function(){var o=(new Date).getTime();if(!(o-n<t))return n=o,e.apply(void 0,arguments)}}IdleTimer.propTypes={timeout:PropTypes.number,events:PropTypes.arrayOf(PropTypes.string),onIdle:PropTypes.func,onActive:PropTypes.func,onAction:PropTypes.func,debounce:PropTypes.number,throttle:PropTypes.number,element:PropTypes.oneOfType([PropTypes.object,PropTypes.element]),startOnMount:PropTypes.bool,stopOnIdle:PropTypes.bool,passive:PropTypes.bool,capture:PropTypes.bool},IdleTimer.defaultProps={timeout:12e5,element:DEFAULT_ELEMENT,events:DEFAULT_EVENTS,onIdle:function(){},onActive:function(){},onAction:function(){},debounce:0,throttle:0,startOnMount:!0,stopOnIdle:!1,capture:!0,passive:!0},module.exports=IdleTimer; | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var react=require("react"),PropTypes=_interopDefault(require("prop-types")),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),inherits=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},possibleConstructorReturn=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},IS_BROWSER="object"===("undefined"==typeof window?"undefined":"undefined"==typeof window?"undefined":_typeof(window)),DEFAULT_ELEMENT=IS_BROWSER?document:{},DEFAULT_EVENTS=["mousemove","keydown","wheel","DOMMouseScroll","mouseWheel","mousedown","touchstart","touchmove","MSPointerDown","MSPointerMove"],IdleTimer=function(e){function t(e){classCallCheck(this,t);var n=possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));if(n.state={idle:!1,oldDate:+new Date,lastActive:+new Date,remaining:null,pageX:null,pageY:null},n.tId=null,n._handleEvent=function(e){var t=n.state,o=t.remaining,i=t.pageX,r=t.pageY,s=t.idle,u=n.props,a=u.timeout,l=u.onAction,p=u.debounce,c=u.throttle,d=u.stopOnIdle;if(p>0?n.debouncedAction(e):c>0?n.throttledAction(e):l(e),!o){if("mousemove"===e.type){if(e.pageX===i&&e.pageY===r)return;if(void 0===e.pageX&&void 0===e.pageY)return;if(n.getElapsedTime()<200)return}clearTimeout(n.tId),n.tId=null,s&&!d&&n.toggleIdleState(e),n.setState({lastActive:+new Date,pageX:e.pageX,pageY:e.pageY}),s&&d||(n.tId=setTimeout(n.toggleIdleState,a))}},e.debounce>0&&e.throttle>0)throw new Error("onAction can either be throttled or debounced (not both)");return e.debounce>0&&(n.debouncedAction=debounced(e.onAction,e.debounce)),e.throttle>0&&(n.throttledAction=throttled(e.onAction,e.throttle)),e.startOnMount||(n.state.idle=!0),n.toggleIdleState=n._toggleIdleState.bind(n),n.reset=n._reset.bind(n),n.pause=n._pause.bind(n),n.resume=n._resume.bind(n),n.getRemainingTime=n._getRemainingTime.bind(n),n.getElapsedTime=n._getElapsedTime.bind(n),n.getLastActiveTime=n._getLastActiveTime.bind(n),n.isIdle=n._isIdle.bind(n),n}return inherits(t,e),createClass(t,[{key:"componentWillMount",value:function(){this._bindEvents()}},{key:"componentDidMount",value:function(){this.props.startOnMount&&this.reset()}},{key:"componentWillUnmount",value:function(){clearTimeout(this.tId),this._unbindEvents()}},{key:"render",value:function(){return this.props.children||null}},{key:"_bindEvents",value:function(){var e=this;if(IS_BROWSER){var t=this.state.eventsBound,n=this.props,o=n.element,i=n.events,r=n.passive,s=n.capture;t||(i.forEach(function(t){o.addEventListener(t,e._handleEvent,{capture:s,passive:r})}),this.setState({eventsBound:!0}))}}},{key:"_unbindEvents",value:function(){var e=this;if(IS_BROWSER){var t=this.props,n=t.element,o=t.events,i=t.passive,r=t.capture;this.state.eventsBound&&(o.forEach(function(t){n.removeEventListener(t,e._handleEvent,{capture:r,passive:i})}),this.setState({eventsBound:!1}))}}},{key:"_toggleIdleState",value:function(e){var t=this,n=this.state.idle,o=this.props,i=o.onActive,r=o.onIdle,s=o.stopOnIdle;this.setState({idle:!n},function(){n?s||(t._bindEvents(),i(e)):(s&&(clearTimeout(t.tId),t.tId=null,t._unbindEvents()),r(e))})}},{key:"_reset",value:function(){clearTimeout(this.tId),this.tId=null,this._bindEvents(),this.setState({idle:!1,oldDate:+new Date,lastActive:this.state.oldDate,remaining:null});var e=this.props.timeout;this.tId=setTimeout(this.toggleIdleState,e)}},{key:"_pause",value:function(){null===this.state.remaining&&(this._unbindEvents(),clearTimeout(this.tId),this.tId=null,this.setState({remaining:this.getRemainingTime()}))}},{key:"_resume",value:function(){var e=this.state,t=e.remaining,n=e.idle;null!==t&&(this._bindEvents(),n||(this.setState({remaining:null}),this.tId=setTimeout(this.toggleIdleState,t)))}},{key:"_getRemainingTime",value:function(){var e=this.state,t=e.remaining,n=e.idle,o=e.lastActive;if(n)return 0;if(null!==t)return t;var i=this.props.timeout-(+new Date-o);return i<0&&(i=0),i}},{key:"_getElapsedTime",value:function(){var e=this.state.oldDate;return+new Date-e}},{key:"_getLastActiveTime",value:function(){return this.state.lastActive}},{key:"_isIdle",value:function(){return this.state.idle}}]),t}(react.Component);function debounced(e,t){var n=void 0;return function(){for(var o=arguments.length,i=Array(o),r=0;r<o;r++)i[r]=arguments[r];n&&clearTimeout(n),n=setTimeout(function(){e.apply(void 0,i),n=null},t)}}function throttled(e,t){var n=0;return function(){var o=(new Date).getTime();if(!(o-n<t))return n=o,e.apply(void 0,arguments)}}IdleTimer.propTypes={timeout:PropTypes.number,events:PropTypes.arrayOf(PropTypes.string),onIdle:PropTypes.func,onActive:PropTypes.func,onAction:PropTypes.func,debounce:PropTypes.number,throttle:PropTypes.number,element:PropTypes.oneOfType([PropTypes.object,PropTypes.element]),startOnMount:PropTypes.bool,stopOnIdle:PropTypes.bool,passive:PropTypes.bool,capture:PropTypes.bool},IdleTimer.defaultProps={timeout:12e5,element:DEFAULT_ELEMENT,events:DEFAULT_EVENTS,onIdle:function(){},onActive:function(){},onAction:function(){},debounce:0,throttle:0,startOnMount:!0,stopOnIdle:!1,capture:!0,passive:!0},module.exports=IdleTimer; | ||
//# sourceMappingURL=index.min.js.map |
{ | ||
"name": "react-idle-timer", | ||
"version": "4.2.1", | ||
"version": "4.2.2", | ||
"description": "Activity detection for React.js", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.min.js", |
@@ -16,14 +16,8 @@ # React Idle Timer | ||
Version `4.2.0` brings typescript support and dynamic event binding to `IdleTimer`: | ||
#### Version `4.2.0` brings typescript support and dynamic event binding to `IdleTimer`: | ||
☝️ Events will now dynamically unbind when they are not needed (`pause()`, `stopOnIdle`) and bound when they are needed (`resume()`, `reset()`, `startOnMount`). If `onAction` is set, events will never be unbound. | ||
✌️ Added a typescript type definition file that will be maintained alongside this library. It requires that you have the react type definitions installed. | ||
✌️ Added a typescript type definition file that will be maintained alongside this library. It requires that you have the react type definitions installed. | ||
Version `4.1.0` brings two of the most requested features to `IdleTimer`: | ||
☝️ You can now use `IdleTimer` as a generic activity monitor via the new `onAction` event handler. We recommend using one of the built in `debounce` or `throttle` properties if you dont need every single update. It really improves performance. | ||
✌️ Added a property `stopOnIdle` that allows developer intervention between the idle and active states. Good for waiting for an async task to complete before restarting the `IdleTimer`. If this option is set, you will have to call `reset()` manually to restart `IdleTimer`. | ||
> For the full patch notes please refer to the [CHANGELOG](https://github.com/SupremeTechnopriest/react-idle-timer/blob/master/CHANGELOG.md) | ||
@@ -30,0 +24,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
67274
-0.59%127
-4.51%