{"id":20596050,"url":"https://github.com/davidfig/loop","last_synced_at":"2025-07-14T16:05:16.512Z","repository":{"id":57404916,"uuid":"106080093","full_name":"davidfig/loop","owner":"davidfig","description":"Simple and configurable game/main loop","archived":false,"fork":false,"pushed_at":"2017-12-21T03:35:28.000Z","size":1218,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-17T13:05:40.665Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/davidfig.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}},"created_at":"2017-10-07T07:41:22.000Z","updated_at":"2022-01-01T15:23:03.000Z","dependencies_parsed_at":"2022-09-03T19:31:06.315Z","dependency_job_id":null,"html_url":"https://github.com/davidfig/loop","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/davidfig/loop","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidfig%2Floop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidfig%2Floop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidfig%2Floop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidfig%2Floop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidfig","download_url":"https://codeload.github.com/davidfig/loop/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidfig%2Floop/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265314186,"owners_count":23745214,"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","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":[],"created_at":"2024-11-16T08:14:53.959Z","updated_at":"2025-07-14T16:05:16.477Z","avatar_url":"https://github.com/davidfig.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yy-loop\nSimple and configurable game/main loop\n\n## features\n* emits events (using eventemitter3)\n* run every frame or after an interval\n* control how many times each function runs\n* loop pauses when app loses focus\n* uses requestAnimationFrame()\n\n## rationale\n\nThis is a replacement for [YY-Update](https://github.com/davidfig/update). I use this in all my games, and as a base class for my other libraries, including [pixi-ease](https://github.com/davidfig/pixi-ease) and [pixi-viewport](https://github.com/davidfig/pixi-viewport).\n\n## installation\n\n    npm i yy-loop\n\n## simple example\n\n    const Loop = require('yy-loop')\n\n    const loop = new Loop()\n\n    // add a function to the loop that logs the elapsed time\n    loop.add((elapsed) =\u003e console.log(elapsed))\n\n    // add a function to the loop that runs ever second for 5 times\n    const entry = loop.add((elapsed) =\u003e console.log(elapsed), 1000, 5)\n\n    // run each time entry is called\n    entry.on('each', () =\u003e console.log('It has been one second.'))\n\n    // run after entry is complete\n    entry.on('done', () =\u003e console.log('completed'))\n\n## live example\nhttps://davidfig.github.io/loop/\n\n## API\n### src/loop.js\n```js\n    /**\n     * basic loop support\n     * @param {object} [options]\n     * @param {number} [options.maxFrameTime=1000/60] maximum time in milliseconds for a frame\n     * @param {object} [options.pauseOnBlur] pause loop when app loses focus, start it when app regains focus\n     *\n     * @event each(elapsed, Loop)\n     * @event start(Loop)\n     * @event stop(Loop)\n     */\n    constructor(options)\n\n    /**\n     * start requestAnimationFrame() loop\n     * @return {Loop} this\n     */\n    start()\n\n    /**\n     * stop loop\n     * @return {Loop} this\n     */\n    stop()\n\n    /**\n     * loop through updates; can be called manually each frame, or called automatically as part of start()\n     * @param {number} elapsed time since last call (will be clamped to this.maxFrameTime)\n     */\n    update(elapsed)\n\n    /**\n     * adds a callback to the loop\n     * @deprecated use add() instead\n     * @param {function} callback\n     * @param {number} [time=0] in milliseconds to call this update (0=every frame)\n     * @param {number} [count=0] number of times to run this update (0=infinite)\n     * @return {object} entry - used to remove or change the parameters of the update\n     */\n    interval(callback, time, count)\n\n    /**\n     * adds a callback to the loop\n     * @param {function} callback\n     * @param {number} [time=0] in milliseconds to call this update (0=every frame)\n     * @param {number} [count=0] number of times to run this update (0=infinite)\n     * @return {object} entry - used to remove or change the parameters of the update\n     */\n    add(callback, time, count)\n\n    /**\n     * adds a one-time callback to the loop\n     * @param {function} callback\n     * @param {number} time in milliseconds to call this update\n     * @return {object} entry - used to remove or change the parameters of the update\n     */\n    timeout(callback, time)\n\n    /**\n     * remove a callback from the loop\n     * @param {object} entry - returned by add()\n     */\n    remove(entry)\n\n    /**\n     * removes all callbacks from the loop\n     */\n    removeAll()\n\n    /**\n     * @type {number} count of all animations\n     */\n    get count()\n\n    /**\n     * @type {number} count of running animations\n     */\n    get countRunning()\n\n```\n### src/entry.js\n```js\n/** Entry class for Loop */\nclass Entry extends Events\n{\n    /**\n     * create an entry in the update loop\n     * used by Loop\n     * @param {function} callback\n     * @param {number} [time=0] in milliseconds to call this update\n     * @param {number} [count] number of times to run this update (undefined=infinite)\n     */\n    constructor(callback, time, count)\n\n    /**\n     * update checks time and runs the callback\n     * @param {number} elapsed\n     * @return {boolean} whether entry is complete and may be removed from list\n     */\n    update(elapsed)\n\n    /**\n     * @type {boolean} pause this entry\n     */\n    set pause(value)\n\n```\n## License  \nMIT License  \n(c) 2017 [YOPEY YOPEY LLC](https://yopeyopey.com/) by [David Figatner](https://twitter.com/yopey_yopey/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidfig%2Floop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidfig%2Floop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidfig%2Floop/lists"}