{"id":19560650,"url":"https://github.com/zoubin/rebounce","last_synced_at":"2025-02-26T08:41:32.777Z","repository":{"id":57349090,"uuid":"41403014","full_name":"zoubin/rebounce","owner":"zoubin","description":"Usefull for implementing behavior that should happen less frequently than default","archived":false,"fork":false,"pushed_at":"2015-08-27T09:41:54.000Z","size":148,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-09T01:35:19.661Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zoubin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-26T03:48:58.000Z","updated_at":"2015-08-26T09:18:18.000Z","dependencies_parsed_at":"2022-08-29T18:21:37.094Z","dependency_job_id":null,"html_url":"https://github.com/zoubin/rebounce","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Frebounce","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Frebounce/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Frebounce/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Frebounce/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zoubin","download_url":"https://codeload.github.com/zoubin/rebounce/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240822615,"owners_count":19863302,"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-11T05:08:22.754Z","updated_at":"2025-02-26T08:41:32.732Z","avatar_url":"https://github.com/zoubin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rebounce\nUsefull for implementing behavior that should happen less frequently than default.\n\n## Example\n\n### Node\n\n```javascript\nvar rebounce = require('rebounce');\n\n// want \nvar rebounced = rebounce(original, 100)\n\n// call `rebounced` every 50ms\n\nfunction original() {\n}\n\n```\n\n```\nTime  Rebounced Original\n----------------------------------------\n0     called    called\n56    called    -\n105   called    called\n157   called    -\n211   called    called\n266   called    -\n317   called    called\n372   called    -\n423   called    called\n476   called    -\n\n```\n\n### browser\n\n```html\n\u003cscript src=\"dist/rebounce.js\" type=\"text/javascript\"\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\"\u003e\n  window.onresize = rebounce(resize, 1000, true);\n  var count = 0;\n  function resize(e) {\n    console.log(count++, '*'.repeat(80));\n    console.log('height', window.innerHeight);\n    console.log('width', window.innerWidth);\n  }\n\u003c/script\u003e\n```\n\n## API\n\n### rebounce(fn, interval, [ once = false ])\nCreates and returns a rebounced version of the passed function\nthat will execute the original `fn` when\neither `fn` has not been called yet,\nor `interval` miliseconds have elapsed since the last execution of `fn`.\n\nHowever, if `once` is set to `true`, `fn` will be called when\neither `fn` has not been called yet,\nor `interval` miliseconds have elapsed since the last execution of **the rebounced version** of `fn`.\n\nSuppose that the rebounced version will be scheduled to execute at intervals\n`[50, 100, 50, 50, 100, 50, 50, 50]`,\nand `interval` is set to `100`, `once` to `false`,\nthen the actual times of execution of `fn` and its rebounced version will be like:\n\n```\nTime  Rebounced Original\n----------------------------------------\n0     1         1\n55    2         -\n161   3         2\n212   4         -\n263   5         3\n366   6         4\n422   7         -\n471   8         5\n527   9         -\n```\n\nIf `once` is set to `true`,\n\n```\nTime  Rebounced Original\n----------------------------------------\n0     1         1\n53    2         -\n156   3         -\n157   -         2\n210   4         -\n266   5         -\n370   6         3\n422   7         -\n474   8         -\n529   9         -\n\n```\n\n\n### risingTrigger v.s. fallingTrigger\nBy default, the rebounced version executes `fn` at the beginning of the `interval`.\nBut you can use `rebounce.fallingTrigger` to execute `fn` at the end.\n\n```javascript\nvar risingTrigger = require('rebounce');\nvar fallingTrigger = require('rebounce').fallingTrigger;\n```\n\nIn the above example,\n\nwhen using `risingTrigger`:\n\n```\nTime  Rebounced Original\n----------------------------------------\n0     1         1\n55    2         -\n161   3         2\n212   4         -\n263   5         3\n366   6         4\n422   7         -\n471   8         5\n527   9         -\n```\n\nwhen using `fallingTrigger`\n\n```\nTime  Rebounced Original\n----------------------------------------\n0     1         -\n57    2         -\n106   -         1\n160   3         -\n216   4         -\n265   -         2\n267   5         -\n371   -         3\n372   6         -\n424   7         -\n472   -         4\n475   8         -\n531   9         -\n581   -         5\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoubin%2Frebounce","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzoubin%2Frebounce","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoubin%2Frebounce/lists"}