{"id":16625622,"url":"https://github.com/aleclarson/rafz","last_synced_at":"2025-10-07T02:57:31.567Z","repository":{"id":66177970,"uuid":"345399023","full_name":"aleclarson/rafz","owner":"aleclarson","description":"Coordinate `requestAnimationFrame` calls across your app and/or libraries","archived":false,"fork":false,"pushed_at":"2021-03-07T16:42:54.000Z","size":28,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-16T03:43:40.521Z","etag":null,"topics":["raf","requestanimationframe"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aleclarson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-03-07T16:42:42.000Z","updated_at":"2024-02-25T18:42:11.000Z","dependencies_parsed_at":"2023-02-20T23:16:08.885Z","dependency_job_id":null,"html_url":"https://github.com/aleclarson/rafz","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/aleclarson/rafz","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleclarson%2Frafz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleclarson%2Frafz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleclarson%2Frafz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleclarson%2Frafz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aleclarson","download_url":"https://codeload.github.com/aleclarson/rafz/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleclarson%2Frafz/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278712683,"owners_count":26032741,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["raf","requestanimationframe"],"created_at":"2024-10-12T04:06:29.380Z","updated_at":"2025-10-07T02:57:31.562Z","avatar_url":"https://github.com/aleclarson.png","language":"TypeScript","readme":"# rafz\n\nCoordinate `requestAnimationFrame` calls across your app and/or libraries.\n\n* \u003c 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\u0026nbsp;\n\n## API\n\n```ts\nimport { raf } from 'rafz'\n\n// Schedule an update\nraf(dt =\u003e {})\n\n// Start an update loop\nraf(dt =\u003e true)\n\n// Cancel an update\nraf.cancel(fn)\n\n// Schedule a mutation\nraf.write(() =\u003e {})\n\n// Before any updates\nraf.onStart(() =\u003e {})\n\n// Before any mutations\nraf.onFrame(() =\u003e {})\n\n// After any mutations\nraf.onFinish(() =\u003e {})\n\n// Set a timeout that runs on nearest frame\nraf.setTimeout(() =\u003e {}, 1000)\n\n// Use a polyfill\nraf.use(require('@essentials/raf').raf)\n\n// Get the current time\nraf.now() // =\u003e number\n```\n\n\u0026nbsp;\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\u0026nbsp;\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(() =\u003e {\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\u0026nbsp;\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\u0026nbsp;\n\n## Prior art\n\n- [fastdom](https://github.com/wilsonpage/fastdom)\n- [framesync](https://github.com/Popmotion/popmotion/tree/master/packages/framesync)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faleclarson%2Frafz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faleclarson%2Frafz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faleclarson%2Frafz/lists"}