{"id":16817064,"url":"https://github.com/phanan/vuebus","last_synced_at":"2025-04-11T02:23:40.479Z","repository":{"id":47999683,"uuid":"122980202","full_name":"phanan/vuebus","owner":"phanan","description":"A simple event bus in Vue 2.x","archived":false,"fork":false,"pushed_at":"2022-07-21T02:02:15.000Z","size":60,"stargazers_count":8,"open_issues_count":8,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T23:51:23.292Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/phanan.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":"2018-02-26T14:19:40.000Z","updated_at":"2023-04-04T11:59:10.000Z","dependencies_parsed_at":"2022-08-12T16:11:38.652Z","dependency_job_id":null,"html_url":"https://github.com/phanan/vuebus","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phanan%2Fvuebus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phanan%2Fvuebus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phanan%2Fvuebus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phanan%2Fvuebus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phanan","download_url":"https://codeload.github.com/phanan/vuebus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248328496,"owners_count":21085325,"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-10-13T10:46:05.446Z","updated_at":"2025-04-11T02:23:40.459Z","avatar_url":"https://github.com/phanan.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# VueBus\n\n\u003e A dead-simple event bus for Vue 2.\n\n## Installation\n\nInstall VueBus with yarn or npm:\n  \n  ```bash\n  yarn add @phanan/vuebus\n  # or\n  npm install @phanan/vuebus\n  ```\n\n## Usage\n\nFirst, import and initialize a new VueBus instance:\n  \n  ```js\n  import VueBus from '@phanan/vuebus'\n\n  const bus = new VueBus()\n  ```\n\n### Emit an event\n\n```js\nbus.emit('userLoggedIn')\nbus.emit('userLoggedIn', 'with', 'additional', data)\n```\n\n### Listen to events\n\nWith VueBus, you can listen and react to one event:\n\n```js\nbus.on('userLoggedIn', () =\u003e this.sayHello())\n```\n\nor an array of events:\n\n```js\nbus.on(['userLoggedIn', 'userLoggedBackIn'], () =\u003e this.sayHello())\n```\n\nBy passing an object of `{ eventName: callbackFunction }` shape, you can listen to several events and react to each of them with a different callback:\n\n```js\nbus.on({\n  userLoggedIn () {\n    this.sayHello()\n  },\n\n  userLoggedOut () {\n    this.sayGoodbye()\n  }\n})\n```\n\n### `once` and `off`\n\nVueBus's `once` and `off` behave exactly like their [Vue](https://vuejs.org/v2/api/#vm-once) [counterparts](https://vuejs.org/v2/api/#vm-off).\n\n### Attach to Vue.prototype\n\nVueBus can attach itself to Vue.prototype and become available as an instance property with the `attach` function . By default, you can access VueBus as `this.$vuebus`, but the property name can be customized by passing a string as an argument. \n\n```js\n(new VueBus()).attach()\n\n// VueBus is now available as a Vue's instance property\nthis.$vuebus.emit('userLoggedIn')\n\n// Use a custom property name\n(new VueBus()).attach('$bus')\nthis.$bus.emit('userLoggedIn')\n```\n\n## License\n\nMIT © [Phan An](https://phanan.net)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphanan%2Fvuebus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphanan%2Fvuebus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphanan%2Fvuebus/lists"}