nanoraf
Only call RAF when needed
Last updated 2 years ago by goto-bus-stop .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install nanoraf 
SYNC missed versions from official npm registry.

nanoraf stability

npm version build status test coverage downloads js-standard-style

Only call RAF when needed.

Usage

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). If omitted, raf defaults to window.requestAnimationFrame.

frame([arguments])

Pass arguments into the render function, to be called on a new tick.

Installation

$ npm install nanoraf

License

MIT

Current Tags

  • 3.1.0                                ...           latest (2 years ago)

10 Versions

  • 3.1.0                                ...           2 years ago
  • 3.0.1                                ...           4 years ago
  • 3.0.0                                ...           4 years ago
  • 2.1.3                                ...           4 years ago
  • 2.1.2                                ...           4 years ago
  • 2.1.1                                ...           4 years ago
  • 2.1.0                                ...           4 years ago
  • 2.0.0                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago

Copyright 2014 - 2016 © taobao.org |