# @smoovy/ticker

> Simple and easy-to-use ticker

Latest version **1.0.4** (published 2025-05-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install @smoovy/ticker
pnpm add @smoovy/ticker
yarn add @smoovy/ticker
bun add @smoovy/ticker
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2025-05-19 |
| First published | 2019-05-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 86 |
| Author | Davide Perozzi |
| Maintainers | davideperozzi |
| Keywords | smoovy, ticker, raf, fps |

## Links

- npm: https://www.npmjs.com/package/@smoovy/ticker
- Repository: https://github.com/davideperozzi/smoovy
- Issues: https://github.com/davideperozzi/smoovy/issues
- npm.io page: https://npm.io/package/@smoovy/ticker

## Recent versions

- 1.0.4 (latest) — 2025-05-19
- 1.0.3 — 2024-12-03
- 1.0.2 — 2023-11-12
- 1.0.1 — 2022-12-28
- 1.0.0 — 2022-12-23
- 0.1.11 — 2020-06-03
- 0.1.10 — 2019-12-11
- 0.1.9 — 2019-12-11
- 0.1.8 — 2019-11-03
- 0.1.7 — 2019-10-18
- 0.1.6 — 2019-09-27
- 0.1.5 — 2019-08-18
- 0.1.4 — 2019-07-29
- 0.1.3 — 2019-07-28
- 0.1.2 — 2019-07-13
- … 3 more at https://npm.io/package/@smoovy/ticker/versions

## README

# @smoovy/ticker
[![Version](https://flat.badgen.net/npm/v/@smoovy/ticker)](https://www.npmjs.com/package/@smoovy/ticker) ![Size](https://flat.badgen.net/bundlephobia/minzip/@smoovy/ticker)

A simple ticker using `requestAnimationFrame`.

## Installation
```sh
yarn add @smoovy/ticker
```
or
```sh
npm install --save @smoovy/ticker
```

## Usage
Import the ticker as usual:
```js
import { Ticker } from '@smoovy/ticker';
```

### Creating a ticker
```js
const ticker = new Ticker();
```

### Listening for the tick
Everytime you start listening for the tick, the ticker creates a new "thread",
which you can control:
```js
const thread = ticker.add(delta => {
  // Animate with delta value
});
```
> The delta value is the time difference to the tick before in milliseconds

To introduce the last two parameters passed to the callback, here's an example on how to kill a thread after 2 seconds:
```js
const thread = ticker.add((delta, time, kill) => {
  if (time >= 2000) {
    kill();
  }
});
```
You can also kill it like this:
```js
setTimeout(() => thread.kill(), 2000);
```
> Once the thread is marked as dead it will be removed on the next animation frame. After that, the reference will be removed.

### Overriding the tick automation
If you want to execute the tick function manually, you can enable the `override` flag. This prevents the internal ticking, after at least one thread is available:
```js
ticker.override = true;
```
You can then call the `tick` method manually:
```js
function tick(time) {
  ticker.tick(
    1    /** A static delta value */,
    time /** Optional time value */
  );

  requestAnimationFrame(tick);
};

requestAnimationFrame(tick);
```

## License
See the [LICENSE](../../LICENSE) file for license rights and limitations (MIT).

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