Skip to content

Commit

Permalink
feat: define enums for isomorphic class
Browse files Browse the repository at this point in the history
  • Loading branch information
dmythro committed Aug 17, 2022
1 parent d8d86c0 commit 7e48e19
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 11 deletions.
27 changes: 25 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions src/IdleDetect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ export class IdleDetect {
public error: (...messages: any[]) => void = defaultNoLog
public log: (...messages: any[]) => void = defaultNoLog

/**
* @param idleSeconds Number of seconds for idle detection, 15 minutes by default
* @param onIdle Event handler when user is idle for specified time
* @param enableLogs
* @param eventTypes
*/
constructor(
/** Number of seconds for idle detection, 15 minutes by default */
idleSeconds: number = defaultIdleTime,
/** Event handler when user is idle for specified time */
onIdle: () => void = defaultNoop,
enableLogs = false,
enableLogs: boolean = false,
eventTypes: string[] = defaultEventTypes,
) {
this.eventTypes = eventTypes
Expand Down
18 changes: 16 additions & 2 deletions src/IdleDetectIsomorph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,29 @@ import { IdleDetect, defaultEventTypes, defaultIdleTime, defaultNoop } from './I

export const isIdleDetectorSupported = () => 'IdleDetector' in window

export enum UserIdleState {
active = 'active',
idle = 'idle',
}

export enum ScreenIdleState {
locked = 'locked',
unlocked = 'unlocked',
}

export class IdleDetectIsomorph extends IdleDetect {
// Native API
protected controller?: AbortController = null
protected detector?: IdleDetector = null

/**
* @param idleSeconds Number of seconds for idle detection, 15 minutes by default
* @param onIdle Event handler when user is idle for specified time
* @param enableLogs
* @param eventTypes
*/
constructor(
/** Number of seconds for idle detection, 15 minutes by default */
idleSeconds: number = defaultIdleTime,
/** Event handler when user is idle for specified time */
onIdle: () => void = defaultNoop,
enableLogs = false,
eventTypes: string[] = defaultEventTypes,
Expand Down
8 changes: 4 additions & 4 deletions src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

declare global {
enum UserIdleState {
'active' = 'active',
'idle' = 'idle',
active = 'active',
idle = 'idle',
}

enum ScreenIdleState {
'locked' = 'locked',
'unlocked' = 'unlocked',
locked = 'locked',
unlocked = 'unlocked',
}

interface IdleDetector {
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { IdleDetectIsomorph } from './IdleDetectIsomorph'

export { UserIdleState, ScreenIdleState } from './IdleDetectIsomorph'

export default IdleDetectIsomorph

0 comments on commit 7e48e19

Please sign in to comment.