# activity-listener

> Respond to ui-events before or after ordinary event-handlers do

Latest version **1.2.0** (published 2021-04-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install activity-listener
pnpm add activity-listener
yarn add activity-listener
bun add activity-listener
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2021-04-14 |
| First published | 2021-02-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 22 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Onno van der Zee |
| Maintainers | ovanderzee |
| Keywords | event, event-handlers, activity, front-end |

## Links

- npm: https://www.npmjs.com/package/activity-listener
- Repository: https://github.com/ovanderzee/activity-listener
- Homepage: https://github.com/ovanderzee/activity-listener#readme
- Issues: https://github.com/ovanderzee/activity-listener/issues
- npm.io page: https://npm.io/package/activity-listener

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 1.2.0 (latest) — 2021-04-14
- 1.1.0 — 2021-02-19

## README

# Activity Listener

Respond to ui-events before or after ordinary event-handlers do.

Usage:
* address obscure tasks:
    blur elements after clicking when peripherals emit enter-keys.

Bad usage:
* cross-tab interaction:
    use localstorage-events or serviceworker messaging
* record user activity:
    you want the [Inactivity Listener](https://www.npmjs.com/package/inactivity-listener)
    for that.

But I can code that myself!
Sure, but this module knows the tricks and can be controlled from different places!

## Install

Install the package as npm package. Provided are
a umd-formatted file in the dist folder to require or just read
and an es-module in the module folder to import.

## Usage

To register calls at the very start an event:
```js
const logoff = function () {
    if (!localStorage.authToken && user.name) {
        loginService.logoff()
    }
}
const eraseClickLogoff = activityListener.register('click', logoff)
```

To register calls at the end of an event's propagation:
```js
const blur = function () {
    const focussed = document.querySelector('*:focus')
    if (focussed) {
        focussed.blur()
    }
}
const eraseClickBlur = activityListener.register('click', undefined, blur)
```

Or to register calls both at the start and the end,
and allow time for the handlers to finish:
```js
const eraseClickRegistration = activityListener.register('click', logoff, blur, 100)
```

To undo the registration:
```js
activityListener.erase('click', logoff)
activityListener.destroy() // erase all
eraseClickRegistration()
```
note that 'clear' is now deprecated

flow methods:
```js
activityListener.pause()
activityListener.resume()
```

## Demo

.../activity-listener/demo/activityListener.html

---
_Source: https://npm.io/package/activity-listener · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
