{"id":16385323,"url":"https://github.com/any86/any-event","last_synced_at":"2025-03-16T16:30:57.992Z","repository":{"id":35076004,"uuid":"159008046","full_name":"any86/any-event","owner":"any86","description":"🍰  不到1k, 一个mini的事件管理器,  希望能在您的代码中做一块砖","archived":false,"fork":false,"pushed_at":"2023-01-05T21:59:47.000Z","size":2094,"stargazers_count":12,"open_issues_count":16,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-06T04:15:39.697Z","etag":null,"topics":["event","eventemitter","events","mini","utils"],"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/any86.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2018-11-25T07:23:57.000Z","updated_at":"2022-01-24T09:31:29.000Z","dependencies_parsed_at":"2023-01-15T13:19:20.026Z","dependency_job_id":null,"html_url":"https://github.com/any86/any-event","commit_stats":null,"previous_names":["383514580/mini-events"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/any86%2Fany-event","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/any86%2Fany-event/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/any86%2Fany-event/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/any86%2Fany-event/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/any86","download_url":"https://codeload.github.com/any86/any-event/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243822283,"owners_count":20353499,"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":["event","eventemitter","events","mini","utils"],"created_at":"2024-10-11T04:14:13.970Z","updated_at":"2025-03-16T16:30:57.681Z","avatar_url":"https://github.com/any86.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# any-event [![NPM Version][npm-image]][npm-url] [![npm bundle size (minified + gzip)][size-image]][size-url] [![codecov][codecov-image]][codecov-url] [![CircleCI][ci-image]][ci-url]\n\n[npm-image]: https://img.shields.io/npm/v/any-event.svg\n[npm-url]: https://npmjs.org/package/any-event\n[downloads-url]: https://npmjs.org/package/any-event\n[size-image]: https://img.shields.io/bundlephobia/minzip/any-event.svg\n[size-url]: https://bundlephobia.com/result?p=any-event\n[codecov-image]: https://codecov.io/gh/any86/any-event/branch/master/graph/badge.svg \n[codecov-url]: https://codecov.io/gh/any86/any-event\n[ci-image]: https://circleci.com/gh/any86/any-event.svg?style=svg\n[ci-url]: https://circleci.com/gh/any86/any-event\n\n:cake: 不到1k, 一个mini的事件管理器,  希望能在您的代码中做一块砖.\n\n\n## 安装\n\n``` shell\nnpm i -S any-event\n```\n\n## 使用\n\n``` javascript\nimport EventEmitter from  'any-event';\nconst emitter = new EventEmitter();\nemitter.on('add', data=\u003e{\n    console.log(data) // 1\n});\nemitter.emit('add', 1);\n```\n## 方法\n\n\n### on(eventName, listener)\n绑定事件\n\n|名称|类型|数据类型|是否必填|说明|\n|---|---|---|---|---|\n|eventName| 参数 |`String/Symbol`|是|事件名称|\n|listener| 参数 |`Function`|是|对应的回调函数|\n|emitter| 返回值 |`EventEmitter`|---|实例|\n\n### off(eventName, listener)\n解除绑定, 如果不填写`listener`, 那么`eventName`对应的`listener`都会被移除.\n\n|名称|类型|数据类型|是否必填|说明|\n|---|---|---|---|---|\n|eventName| 参数 |`String/Symbol`|是|事件名称|\n|listener| 参数 |`Function`|是|对应的回调函数|\n|emitter| 返回值 |`EventEmitter`|---|实例|\n\n``` javascript\nconst callback = data=\u003e{\n    alert(data)\n};\nemitter.on('add', callback);\n// 解除绑定\nemitter.off('add', callback);\n// add事件不会触发\nemitter.emit('add', 1);\n```\n\n\n### emit(eventName [, ...args])\n触发事件, 支持任意数量参数\n\n|名称|类型|数据类型|是否必填|说明|\n|---|---|---|---|---|\n|eventName| 参数 |`String/Symbol`|是|事件名称|\n| args| 参数 |`Any`|是|数据|\n|emitter| 返回值 |`Boolean`|---|实例|\n\n``` javascript\nconst callback = (a,b,c,d)=\u003e{\n    console(a,b,c,d); // 1,2,3,4\n};\nemitter.once('add', callback);\n// add事件触发\nemitter.emit('add', 1,2,3,4);\n```\n\n\n### destroy()\n销毁实例\n\n``` javascript\nconst callback = (a,b,c,d)=\u003e{\n    console(a,b,c,d); // 1,2,3,4\n};\nemitter.once('add', callback);\nemitter.destroy();\n\n// add事件不会触发\nemitter.emit('add', 1,2,3,4);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fany86%2Fany-event","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fany86%2Fany-event","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fany86%2Fany-event/lists"}