Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cache-per-frame

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache-per-frame

Cache the result of a function once per frame

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

cache-per-frame

Build Status Build Status Build Status Build Status

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:

<script src='cache-per-frame.js'></script>
<script>
var nativeGetFrameData = VRDisplay.prototype.getFrameData;
VRDisplay.prototype.getFrameData = cachePerFrame(function (fd) {
  return nativeGetFrameData.call(this, fd);
});
</script>

Or install via npm/yarn:

$ npm install cache-per-frame --save

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)

FAQs

Package last updated on 25 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc