UNPKG

redux-active

Version:
2 lines (1 loc) 1.09 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const IS_IDLE="@@active/IS_IDLE",IS_ACTIVE="@@active/IS_ACTIVE",injectThrottle=e=>({eventTarget:t=window,eventThrottleTimeout:r=250,eventTypes:o=["click","focus","keydown","mousemove","resize","scroll","touchmove","wheel"],idleCheckInterval:i=1e3,idleTimeout:c=6e4,stateSelector:a=(e=>e.isActive),throttle:l=e||require("lodash/throttle")}={})=>{let d=+new Date;return({dispatch:e,getState:I})=>{if(void 0===a(I()))return console.error("Error: redux-active has detected a problem with your stateSelector configuration!"),e=>t=>e(t);setInterval(()=>{+new Date-d>c&&a(I())&&e({type:IS_IDLE,payload:{idleTimeout:c}})},i);const n=l(t=>{d=+new Date,a(I())||e({type:IS_ACTIVE,payload:{idleTimeout:c,eventType:t.type}})},r);return o.forEach(e=>t.addEventListener(e,n,!0)),e=>t=>e(t)}},activeReducer=(e=!0,{type:t})=>t!==IS_IDLE&&(t===IS_ACTIVE||e),createActiveMiddleware=injectThrottle();exports.createActiveMiddleware=createActiveMiddleware,exports.activeReducer=activeReducer,exports.IS_ACTIVE=IS_ACTIVE,exports.IS_IDLE=IS_IDLE;