# nanoraf

> Only call RAF when needed

Latest version **3.1.0** (published 2018-07-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install nanoraf
pnpm add nanoraf
yarn add nanoraf
bun add nanoraf
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2018-07-17 |
| First published | 2016-07-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 71 |
| Maintainers | ahdinosaur, almost, amongiants, benlyn, bret, colingourlay, emilbayes, feross, freeman-lab, goto-bus-stop, graforlock, jameskyburz, juliangruber, lrlna, maxogden, s3ththompson, sethvincent, shama, slaskis, substack, timwis, toddself, tornqvist, ungoldman, yerkopalma, yoshuawuyts |
| Keywords | raf |

## Links

- npm: https://www.npmjs.com/package/nanoraf
- Repository: https://github.com/choojs/nanoraf
- Homepage: https://github.com/choojs/nanoraf#readme
- Issues: https://github.com/choojs/nanoraf/issues
- npm.io page: https://npm.io/package/nanoraf

## Dependencies (1)

- [nanoassert](https://npm.io/package/nanoassert.md) ^1.1.0

## Recent versions

- 3.1.0 (latest) — 2018-07-17
- 3.0.1 — 2017-03-23
- 3.0.0 — 2017-03-02
- 2.1.3 — 2017-02-08
- 2.1.2 — 2017-01-03
- 2.1.1 — 2016-07-16
- 2.1.0 — 2016-07-06
- 2.0.0 — 2016-07-05
- 1.0.1 — 2016-07-05
- 1.0.0 — 2016-07-05

## README

# nanoraf [![stability][0]][1]
[![npm version][2]][3] [![build status][4]][5] [![test coverage][6]][7]
[![downloads][8]][9] [![js-standard-style][10]][11]

Only call RAF when needed.

## Usage
```js
var nanoraf = require('nanoraf')
var prev = null

var frame = nanoraf(function render (state) {
  console.log(state.now)
})

updateState({ now: date.now() })
updateState({ now: date.now() })
updateState({ now: date.now() })
updateState({ now: date.now() })

function updateState (state) {
  prev = prev || {}
  frame(state, prev)
  prev = state
}
```

## API
### frame = nanoraf(render, raf?)
Wrap a `render` function that is called on every `raf` tick. If no new state is
available, it will not tick. Passes the last version of the state on every tick.

Optionally, provide an implementation of `requestAnimationFrame` via the
`raf` parameter (for example, the one provided by the [raf
package](https://www.npmjs.com/package/raf)).  If omitted, `raf` defaults to
`window.requestAnimationFrame`.

### frame([arguments])
Pass arguments into the render function, to be called on a new tick.

## Installation
```sh
$ npm install nanoraf
```

## License
[MIT](https://tldrlegal.com/license/mit-license)

[0]: https://img.shields.io/badge/stability-experimental-orange.svg?style=flat-square
[1]: https://nodejs.org/api/documentation.html#documentation_stability_index
[2]: https://img.shields.io/npm/v/nanoraf.svg?style=flat-square
[3]: https://npmjs.org/package/nanoraf
[4]: https://img.shields.io/travis/yoshuawuyts/nanoraf/master.svg?style=flat-square
[5]: https://travis-ci.org/yoshuawuyts/nanoraf
[6]: https://img.shields.io/codecov/c/github/yoshuawuyts/nanoraf/master.svg?style=flat-square
[7]: https://codecov.io/github/yoshuawuyts/nanoraf
[8]: http://img.shields.io/npm/dm/nanoraf.svg?style=flat-square
[9]: https://npmjs.org/package/nanoraf
[10]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square
[11]: https://github.com/feross/standard

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