{"bugs":{"url":"https://github.com/alloc/rafz/issues"},"dist":{"shasum":"635483fe65350792e4ee6234676a6647337cda3a","tarball":"https://registry.npmjs.org/rafz/-/rafz-0.2.0-2.tgz","fileCount":69,"integrity":"sha512-3K2EAqGNWJhHXYqDGw9h8zdcmQD2Rcl1gERocGscHKevNCJdVXmT2jaIXU16fGI6i/1Zhp6YkP3RzSkJaCphHQ==","signatures":[{"sig":"MEUCIGKp8Cr9nSDxdaDei6uDJJqsXQsVaGiezBNxuq3dUAwhAiEA0vBHUBpKROhtIt5zPdQ6P4IUJSl9N6A3W0nPTho39PY=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":64802,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhGGUyCRA9TVsSAnZWagAAP7QP/iBHNzhoz6Bb8PJkq1nV\nQquJX2h+UQ6SHfFJagFmi6QdMGrkSASPjcUPppOau0J5ZKKR1lsQkuEKHRNq\nhaeiPF/3R4Vx4G09TJ+9rAMeNlomQcx/RHj21/tFaYUZvTnhVVDTHsiLMWlD\np8zyShJEwdptCc4LEGkYz+e777MAg4QOSv9ea3BySzCaiNxxjXgqwJlakF3a\n4sqhGXuouBMo2PK/fF8v1rJHJbMejkP1K0fWrdmXlPxv7Dji6rBdQcpD1UBZ\nWwW3DJHjx6aAFAuHsPzRHnAAnvs3WaHLl2Z3/f3FnKQ8GUp0OsmxzFCYrfdL\nPXlyJjSYfz0nGe3AiQmpZz6HAkQJScLPwJrr9uyjjL5K0AMwDLMIpfLqLxS9\nVqVpMkPrOTFETmneD6CBW2n8MfoxkRLUBJdZ8eRe8eABZcJgCmtyLn7M+rme\nnfYxamrkS39Poh0vyrhmEnw3AJ9cbmkIEUbrj+yVU3gIlAr7s2E0h4IB3NEl\n0RobVjEN/sWgN8xGOT1BPbBos3b88w/6k36d/sT3PzgnjKakRwcky+z5wPyf\ntinUdMkfPq0+FVxgfI0kaVADH90wEtWa1b7kKvRyKrVuVhEnG8iKK9Vzr9JZ\nfBHo2dmw8Y2LjCWvTNwpcNiV5ya9/3/mraep3i8XtATcdzEPEVJ4CLsGsy/D\nNZNW\r\n=2o0H\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":"eb3d0b9b0b7abd10d780bbddb0c27245cf1f768f","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.19.1","description":"requestAnimationFrame for libraries","directories":{},"maintainers":[{"name":"aleclarson","email":"aleclarson@protonmail.com"}],"_nodeVersion":"16.5.0","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-2_1628988722407_0.36180819317889856","host":"s3://npm-registry-packages"},"_id":"rafz@0.2.0-2","version":"0.2.0-2"}