@@ -31,7 +31,9 @@ if (typeof document.hidden !== 'undefined') {
3131 const prefixes = [ 'webkit' , 'moz' , 'ms' ]
3232 for ( let i = 0 ; i < prefixes . length ; i ++ ) {
3333 const prefix = prefixes [ i ]
34- if ( typeof ( document as unknown as Record < string , unknown > ) [ `${ prefix } Hidden` ] !== 'undefined' ) {
34+ if (
35+ typeof ( document as unknown as Record < string , unknown > ) [ `${ prefix } Hidden` ] !== 'undefined'
36+ ) {
3537 hidden = `${ prefix } Hidden` as 'hidden'
3638 visibilityChangeEvent = `${ prefix } visibilitychange` as 'visibilitychange'
3739 break
@@ -62,7 +64,7 @@ interface ActivityDetectorParams {
6264 initialState ?: State
6365 autoInit ?: boolean
6466}
65- function createActivityDetector ( {
67+ function createActivityDetector ( {
6668 activityEvents = DEFAULT_ACTIVITY_EVENTS ,
6769 inactivityEvents = DEFAULT_INACTIVITY_EVENTS ,
6870 ignoredEventsWhenIdle = DEFAULT_IGNORED_EVENTS_WHEN_IDLE ,
@@ -81,7 +83,7 @@ function createActivityDetector ({
8183 }
8284 if ( state !== newState ) {
8385 state = newState
84- listeners [ state ] . forEach ( l => l ( ) )
86+ listeners [ state ] . forEach ( ( l ) => l ( ) )
8587 }
8688 }
8789
@@ -104,21 +106,22 @@ function createActivityDetector ({
104106 */
105107 const init = ( firstState = DEFAULT_INITIAL_STATE ) => {
106108 setState ( firstState === State . active ? State . active : State . idle )
107- activityEvents . forEach ( eventName =>
108- window . addEventListener ( eventName , handleUserActivityEvent ) )
109+ activityEvents . forEach ( ( eventName ) =>
110+ window . addEventListener ( eventName , handleUserActivityEvent )
111+ )
109112
110- inactivityEvents . filter ( eventName => eventName !== 'visibilitychange' )
111- . forEach ( eventName =>
112- window . addEventListener ( eventName , handleUserInactivityEvent ) )
113+ inactivityEvents
114+ . filter ( ( eventName ) => eventName !== 'visibilitychange' )
115+ . forEach ( ( eventName ) => window . addEventListener ( eventName , handleUserInactivityEvent ) )
113116
114117 if ( inactivityEvents . indexOf ( 'visibilitychange' ) >= 0 && visibilityChangeEvent != null ) {
115118 document . addEventListener ( visibilityChangeEvent , handleVisibilityChangeEvent )
116119 }
117120 }
118121
119122 /**
120- * Register an event listener for the required event
121- */
123+ * Register an event listener for the required event
124+ */
122125 const on = ( eventName : State , listener : ( ) => void ) => {
123126 listeners [ eventName ] . push ( listener )
124127 const off = ( ) => {
@@ -131,19 +134,21 @@ function createActivityDetector ({
131134 }
132135
133136 /**
134- * Stops the activity detector and clean the listeners
135- */
137+ * Stops the activity detector and clean the listeners
138+ */
136139 const stop = ( ) => {
137140 listeners [ State . active ] = [ ]
138141 listeners [ State . idle ] = [ ]
139142
140143 clearTimeout ( timer )
141144
142- activityEvents . forEach ( eventName =>
143- window . removeEventListener ( eventName , handleUserActivityEvent ) )
145+ activityEvents . forEach ( ( eventName ) =>
146+ window . removeEventListener ( eventName , handleUserActivityEvent )
147+ )
144148
145- inactivityEvents . forEach ( eventName =>
146- window . removeEventListener ( eventName , handleUserInactivityEvent ) )
149+ inactivityEvents . forEach ( ( eventName ) =>
150+ window . removeEventListener ( eventName , handleUserInactivityEvent )
151+ )
147152
148153 if ( visibilityChangeEvent != null ) {
149154 document . removeEventListener ( visibilityChangeEvent , handleVisibilityChangeEvent )
@@ -157,7 +162,7 @@ function createActivityDetector ({
157162 return { on, stop, init }
158163}
159164
160- export default function useIsUserActive ( timeToIdle : number ) : boolean {
165+ export default function useIsUserActive ( timeToIdle : number ) : boolean {
161166 const [ active , setActive ] = useState ( true )
162167 useEffect ( ( ) => {
163168 const activityDetector = createActivityDetector ( {
0 commit comments