{"id":25098365,"url":"https://github.com/supercll/eventhub","last_synced_at":"2025-04-02T04:10:41.134Z","repository":{"id":124739366,"uuid":"300553373","full_name":"supercll/EventHub","owner":"supercll","description":"a simple eventhub for vue","archived":false,"fork":false,"pushed_at":"2022-09-03T14:17:06.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-07T18:51:35.140Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/supercll.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-02T08:40:39.000Z","updated_at":"2022-09-03T14:17:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"f5b1404f-3f58-42a7-851f-0e1bb8d3c997","html_url":"https://github.com/supercll/EventHub","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supercll%2FEventHub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supercll%2FEventHub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supercll%2FEventHub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supercll%2FEventHub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/supercll","download_url":"https://codeload.github.com/supercll/EventHub/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246752656,"owners_count":20827987,"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":"2025-02-07T18:31:15.129Z","updated_at":"2025-04-02T04:10:41.129Z","avatar_url":"https://github.com/supercll.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EventHub\na simple eventhub for vue\n\n# 使用方法\n见test.js文件\n\n# 存在问题：执行off产生数组塌陷\n因为每次都是使用splice来切割数组的，所以off之后的事件直接消失，后面的事件就往前补空缺，使得下标index改变\n```\nconst eventHub = new EventHub();\nfunction fn1() {\n    console.log(1);\n}\nfunction fn2() {\n    console.log(2);\n}\nfunction fn3() {\n    console.log(3);\n    eventHub.off(\"init\", fn1);\n    eventHub.off(\"init\", fn2);\n    eventHub.off(\"init\", fn3);\n}\nfunction fn4() {\n    console.log(4);\n}\nfunction fn5() {\n    console.log(5);\n}\nfunction fn6() {\n    console.log(6);\n}\neventHub.on(\"init\", fn1);\neventHub.on(\"init\", fn2);\neventHub.on(\"init\", fn3);\neventHub.on(\"init\", fn4);\neventHub.on(\"init\", fn5);\neventHub.on(\"init\", fn6);\nconsole.log(\"第一次执行事件\");\neventHub.emit(\"init\");\nconsole.log(\"第二次执行事件\");\neventHub.emit(\"init\");\n```\n# 解决办法\n如果有off取消事件，就先将off的事件指向null\n在下一次emit触发事件的时候再重构事件数组\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupercll%2Feventhub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsupercll%2Feventhub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupercll%2Feventhub/lists"}