activity-detector
activity-detector copied to clipboard
Add type definitions
@atabel, It would be great if you can add support for type definitions.
this seems to work for me:
declare module "activity-detector" {
export type ActivityState = "idle" | "active";
export type ActivityDetectorOptions = {
/**
* Events which force a transition to 'active'
*
* Default:
* [ 'click', 'mousemove', 'keydown', 'DOMMouseScroll',
* 'mousewheel', 'mousedown', 'touchstart', 'touchmove',
* 'focus' ];
*/
activityEvents?: Array<string>;
/**
* Events which force a transition to 'idle'
*
* Default: ['blur', 'visibilitychange']
*/
inactivityEvents?: Array<string>;
/**
* Events that are ignored in 'idle' state
*
* Default: ['mousemove']
*/
ignoredEventsWhenIdle?: Array<string>;
/**
* Inactivity time in ms to transition to 'idle'
*/
timeToIdle?: number;
initialState?: ActivityState;
autoInit?: boolean;
};
export type ActivityDetectorInstance = {
on: (eventName: ActivityState, listener: () => void) => void;
stop: () => void;
init: (firstState: ActivityState) => {};
};
function createActivityDetector(
options: ActivityDetectorOptions
): ActivityDetectorInstance;
export default createActivityDetector;
}
you should then be able to use it like this:
import createActivityDetector, { ActivityDetectorOptions } from "activity-detector";
Nice @archaeron, you should submit a PR with that to https://github.com/DefinitelyTyped/DefinitelyTyped
I'm not using this anymore. This was at an other job.
@archaeron but the thing is still open source and that types will help another devs...
I understand, but I don't even have a project anymore to test this out. But I'm happy for someone else to use the code