Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jsantell/cache-per-frame
Cache the result of a function once per frame
https://github.com/jsantell/cache-per-frame
Last synced: about 2 months ago
JSON representation
Cache the result of a function once per frame
- Host: GitHub
- URL: https://github.com/jsantell/cache-per-frame
- Owner: jsantell
- License: apache-2.0
- Created: 2017-09-25T18:24:22.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-09-25T19:53:08.000Z (over 7 years ago)
- Last Synced: 2024-11-17T04:53:30.917Z (2 months ago)
- Language: JavaScript
- Size: 26.4 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cache-per-frame
[![Build Status](http://img.shields.io/travis/jsantell/cache-per-frame.svg?style=flat-square)](https://travis-ci.org/jsantell/cache-per-frame)
[![Build Status](http://img.shields.io/npm/v/cache-per-frame.svg?style=flat-square)](https://www.npmjs.org/package/cache-per-frame)
[![Build Status](http://img.shields.io/npm/dt/cache-per-frame.svg?style=flat-square)](https://www.npmjs.org/package/cache-per-frame)
[![Build Status](http://img.shields.io/npm/l/cache-per-frame.svg?style=flat-square)](https://www.npmjs.org/package/cache-per-frame)Cache the result of a function once per frame. Built for `VRDisplay.getFrameData(frameData)`
when working with several third party modules that call this once per frame. Does **not**
memoize via arguments, but only uses the arguments from the first call to the wrapped
function per frame.## Install & Usage
Use the browser-ready bundle at [dist/cache-per-frame.js]:
```html
var nativeGetFrameData = VRDisplay.prototype.getFrameData;
VRDisplay.prototype.getFrameData = cachePerFrame(function (fd) {
return nativeGetFrameData.call(this, fd);
});```
Or install via npm/yarn:
`$ npm install cache-per-frame --save`
```js
const cachePerFrame = require('cache-per-frame');var nativeGetFrameData = VRDisplay.prototype.getFrameData;
VRDisplay.prototype.getFrameData = cachePerFrame(function (fd) {
return nativeGetFrameData.call(this, fd);
});
```## API
The root module is a function `cachePerFrame(fn)` that takes a function `fn` and returns
a new wrapped form of that function that is throttled per frame. This wrapped function
also has two additional methods for stopping and starting the throttling. By default,
the wrapped function is already started.### wrappedFn.stop()
Stop throttling the function calls once per frame.
### wrappedFn.start()
Start throttling the function calls once per frame.
## License
Apache License Version 2.0 (see [LICENSE])
[LICENSE]: LICENSE
[dist/cache-per-frame.js]: dist/cache-per-frame.js