{"bugs":{"url":"https://github.com/alloc/rafz/issues"},"dist":{"shasum":"f7a910eb3a82d38e70dfb7e93cf2d8d87b003dcf","tarball":"https://registry.npmjs.org/rafz/-/rafz-0.2.0-0.tgz","fileCount":69,"integrity":"sha512-3l0Tm/OM5lJQgksQxA0RN3buwjSbwKM8ll6HcXHC9fRwCjkdqiQ9UL3su+A8AlrfDzefor4yw+yW4+tCaXsDqA==","signatures":[{"sig":"MEUCIQDJfvna4uwq4TMzM/oHRlnTAyjyen3FTm6V2Mi9i6GHOQIgMEjYuxglRqvT0G626qwxPapARSXLtwwPAt4zJR00K0k=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":61823,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJged7tCRA9TVsSAnZWagAAVtIP/3Th3Xc1mq4GB+TTxv1I\n/SDyztCFuoMY96fop5vCpX7zE7zlkY+eQBTNNxyo6Jb+kuANz02ecArYfovu\nJQSlFEm8iYrBHngw+/B7mLcT5PzTCIA2HUhDdG4fAL4IBRvNl4KIKZUnN7IV\ny2N3+3/hj2KaQN8Oq+vOIr4cPoZE1U8UEUwBs+1C2hauQtuGJkxTM1aCofzN\nn3d21EnWO8UceJys/4tQDZeMEgdo124V6rCLdxbpo8cb4ixnQYTfOGgoV/XS\nxly6mQ9v++vo2nvkVWQLyTR6snaTDagdEi4WRM3UxrGxu9jWpvJV2mmiNzLr\nFlQfQ0rzEuKJCESeqNsBM5zlLeVC/Ka8eOGADgnVvpLltgJKDVeaSb4dBzq4\nQf+6cPaljeSn4bEGVcoXF4EA/A+EaMtSKU+08YS//fs0XkfDJncOQj+asBT0\nAURB0+uf1VneEI7sqdTy660+1C06w32ZqlqiGXZQob4QxmxiHIfSu+jNWvhR\nBxGokOSTCwR6EWbtxXQrQfhaTqS9+rqGtelPZzKronJM9GjYqfWDA3dyH4Bg\nu2E0XC/enG3MM/qLDYehnDLEbTTDU0k6J9RR92lc5Jtd15Vr2iqvq8kR1Kzj\nnI98OwaPvZ0PxpB3wDMG+cVCiTEReVuF5+Wgao4OlOeNK2Khay3WdC+VSoZE\nUEUx\r\n=HCDn\r\n-----END PGP SIGNATURE-----\r\n"},"main":"cjs/raf.js","name":"rafz","author":{"name":"Alec Larson"},"module":"esm/raf.js","readme":"# rafz\n\nCoordinate `requestAnimationFrame` calls across your app and/or libraries.\n\n* < 700 bytes min+gzip\n* Timeout support\n* Batching support (eg: `ReactDOM.unstable_batchedUpdates`)\n* Uncaught errors are isolated\n* Runs continuously (to reduce frame skips)\n\n&nbsp;\n\n## API\n\n```ts\nimport { raf } from 'rafz'\n\n// Schedule an update\nraf(dt => {})\n\n// Start an update loop\nraf(dt => true)\n\n// Cancel an update\nraf.cancel(fn)\n\n// Schedule a mutation\nraf.write(() => {})\n\n// Before any updates\nraf.onStart(() => {})\n\n// Before any mutations\nraf.onFrame(() => {})\n\n// After any mutations\nraf.onFinish(() => {})\n\n// Set a timeout that runs on nearest frame\nraf.setTimeout(() => {}, 1000)\n\n// Use a polyfill\nraf.use(require('@essentials/raf').raf)\n\n// Get the current time\nraf.now() // => number\n```\n\n&nbsp;\n\n## Notes\n\n* Functions can only be scheduled once per queue per frame.\n* Thus, trying to schedule a function twice is a no-op.\n* The `update` phase is for updating JS state (eg: advancing an animation).\n* The `write` phase is for updating native state (eg: mutating the DOM).\n* [Reading] is allowed any time before the `write` phase.\n* Writing is allowed any time after the `onFrame` phase.\n* Timeout handlers run first on each frame.\n* Any handler (except timeouts) can return `true` to run again next frame.\n* The `raf.cancel` function only works with `raf` handlers.\n* Use `raf.sync` to disable scheduling in its callback.\n* Override `raf.batchedUpdates` to avoid excessive re-rendering in React.\n\n[Reading]: https://gist.github.com/paulirish/5d52fb081b3570c81e3a\n\n&nbsp;\n\n## `raf.throttle`\n\nWrap a function to limit its execution to once per frame. If called more than once\nin a single frame, the last arguments are used.\n\n```ts\nlet log = raf.throttle(console.log)\n\nlog(1)\nlog(2) // nothing logged yet\n\nraf.onStart(() => {\n  // \"2\" is logged by now\n})\n\n// Cancel a pending call.\nlog.cancel()\n\n// Access the wrapped function.\nlog.handler\n```\n\n&nbsp;\n\n## Used by\n\n- [react-spring](https://github.com/pmndrs/react-spring)\n- [react-three-fiber](https://github.com/pmndrs/react-three-fiber)\n- [use-element-size](https://github.com/alloc/use-element-size)\n\n&nbsp;\n\n## Prior art\n\n- [fastdom](https://github.com/wilsonpage/fastdom)\n- [framesync](https://github.com/Popmotion/popmotion/tree/master/packages/framesync)\n","gitHead":"6838dc057d60140fdeb492f462a7edeac4576d91","license":"MIT","scripts":{"test":"jest","build":"tsc -p . --outDir esm && tsc -p . --module commonjs --outDir cjs","prepare":"yarn build && node scripts/prepare"},"_npmUser":{"name":"aleclarson","email":"aleclarson@protonmail.com"},"homepage":"https://github.com/alloc/rafz#readme","keywords":["raf","requestAnimationFrame","frameloop","animation","tiny"],"repository":{"url":"git+https://github.com/alloc/rafz.git","type":"git"},"_npmVersion":"7.10.0","description":"requestAnimationFrame for libraries","directories":{},"maintainers":[{"name":"aleclarson","email":"aleclarson@protonmail.com"}],"_nodeVersion":"14.13.1","dependencies":{"react-batched-updates":"^1.0.0"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jest":"^26.6.3","saxon":"^0.2.11","esbuild":"^0.11.3","prettier":"^2.2.1","@cush/exec":"^1.7.1","typescript":"^4.0.0","@types/jest":"^26.0.22","esbuild-jest":"npm:@alloc/esbuild-jest@^0.3.5"},"_npmOperationalInternal":{"tmp":"tmp/rafz_0.2.0-0_1618599660437_0.4441329938763592","host":"s3://npm-registry-packages"},"_id":"rafz@0.2.0-0","version":"0.2.0-0"}