{"name":"framesync","version":"0.4.0","description":"A high-performance, frame-synced render loop for any JavaScript environment.","author":{"name":"Matt Perry","email":"sirhound@popmotion.io"},"homepage":"http://popmotion.io","main":"./lib/framesync.js","files":["lib","framesync.global.js","framesync.global.min.js"],"repository":{"type":"git","url":"git+https://github.com/Popmotion/framesync.git"},"bugs":{"url":"https://github.com/Popmotion/framesync/issues"},"keywords":["requestAnimationFrame","animation"],"analyze":true,"license":"MIT","scripts":{"compile":"babel src --out-dir lib && NODE_ENV=production webpack","watch":"NODE_ENV=development webpack --progress --colors --watch","measure":"gzip -c framesync.global.min.js | wc -c","test":"mocha --compilers js:babel-core/register"},"devDependencies":{"babel-core":"^6.0.20","babel-loader":"^6.0.1","babel-preset-es2015-subset-loose":"^1.0.0","babel-preset-stage-2":"^6.0.15","babel-register":"^6.3.13","chai":"^3.4.0","jshint":"^2.8.0","jshint-loader":"^0.8.3","webpack":"1.7.2"},"gitHead":"d9ee6e311fb31639bfe8ddec638d9026a6e38663","_id":"framesync@0.4.0","_shasum":"5562bd7c89ef1aed98f0092d6c53be27a9c270d9","_from":".","_npmVersion":"3.3.6","_nodeVersion":"5.0.0","_npmUser":{"name":"popmotion","email":"sirhound@popmotion.io"},"dist":{"shasum":"5562bd7c89ef1aed98f0092d6c53be27a9c270d9","tarball":"http://registry-npm.ywwl.com/framesync/download/framesync-0.4.0.tgz","integrity":"sha512-kaiNaaJDYkA/P9wXcAUqNEfy9oQ9KyDvsIVvWvuxqnlH+08fBMshQy5+pi1xKqKOyjL6iB3bJh+WG6MdKQR/0w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHpSFM6wzvjMH+IgS1yG8tRqgQ/T12EMhgyzu3WBDRhxAiEA12+ffeGqedR8baNqSNe/YIrQd610pRIyM4jTiNZXNKI="}],"size":38475,"noattachment":false,"key":"/framesync/-/framesync-0.4.0.tgz"},"maintainers":[{"name":"popmotion","email":"sirhound@popmotion.io"}],"directories":{},"readme":"# Framesync\n\nA tiny frame scheduler for performantly batching reads, updates and renders.\n\nSegregating actions that read and write to the DOM will avoid [layout thrashing](https://developers.google.com/web/fundamentals/performance/rendering/avoid-large-complex-layouts-and-layout-thrashing).\n\nIt's also a way of ensuring order of execution across a frame. For instance, [Framer Motion](https://github.com/framer/motion) batches animations on the `update` step, and renders on the `render` step, allowing independent animation of `transform` properties.\n\n## Install\n\n```bash\nnpm install framesync\n```\n\n## Usage\n\nFramesync splits a frame into discrete `read`, `update`, `preRender`, `render` and `postRender` steps.\n\n### Scheduling functions\n\nFunctions can be scheduled to different parts of the render loop with `sync`.\n\n```javascript\nimport sync from 'framesync';\n```\n\nIt provides four functions, one for scheduling a function to run on each part of the frame:\n\n```javascript\nsync.update(() => {});\n```\n\n### Frame data\n\nEach function is provided data about the current frame:\n\n```javascript\nsync.update(({ delta, timestamp }) => {});\n```\n\n- `delta`: Time since last frame (in milliseconds)\n- `timestamp`: Timestamp of the current frame.\n\nThis object is recycled across frames, so values should be destructured if intended to be used asynchronously.\n\n### Keep alive\n\nWe can run a function as an ongoing process by passing `true` as the second parameter:\n\n```javascript\nlet count = 0;\n\nsync.update(() => count++, true);\n```\n\nThis will keep the process running until it's actively cancelled.\n\n### Run immediately\n\nThe third parameter, `immediate`, can be used to sync a function on the **current frame step**.\n\nBy default, Framesync will schedule functions to run the next time that frame step is fired:\n\n```javascript\nsync.update(({ timestamp }) => {\n  // The following function will run on the subsequent frame:\n  sync.update((frame) => frame.timestamp !== timestamp);\n});\n```\n\nBy setting `immediate` to `true`, we can add this at the end of the current step:\n\n```javascript\nsync.update(({ timestamp }) => {\n  // The following function will run on the **current** frame:\n  sync.update(\n    (frame) => frame.timestamp === timestamp,\n    false,\n    true\n  );\n});\n```\n\n### Cancelling\n\nSynced processes can be cancelled with the `cancelSync` function:\n\n```javascript\nimport sync, { cancelSync } from 'framesync';\n\nlet count = 0;\n\nconst process = sync.render(() => {\n  count++;\n  if (count >= 10) cancelSync.render(process);\n}, true);\n```\n","publish_time":1452252322115,"_cnpm_publish_time":1452252322115,"dist-tags":{"latest":"6.1.2","rc":"6.0.0-rc.1"}}