Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/betterwrite/vue-pubsub
A Pubsub Plugin (or better Event Bus) for Vue.
https://github.com/betterwrite/vue-pubsub
event-bus mitt pubsub typescript vue vue3 vuejs
Last synced: 4 days ago
JSON representation
A Pubsub Plugin (or better Event Bus) for Vue.
- Host: GitHub
- URL: https://github.com/betterwrite/vue-pubsub
- Owner: betterwrite
- Created: 2023-03-30T14:26:55.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-30T14:37:03.000Z (almost 2 years ago)
- Last Synced: 2024-12-23T07:09:29.315Z (about 1 month ago)
- Topics: event-bus, mitt, pubsub, typescript, vue, vue3, vuejs
- Language: TypeScript
- Homepage:
- Size: 41 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Vue Pubsub
A Pubsub Plugin (or better Event Bus) for Vue, inspired in [mitt](https://github.com/developit/mitt)
### Use
`npm i vue-pubsub`
```typescript
import { createApp } from "vue";
import { PubsubPlugin } from "vue-pubsub";
import App from "./App.vue";const app = createApp(App);
app.use(PubsubPlugin());
app.mount("#app");// ...
import { usePubsub } from "vue-pubsub";
const pubsub = usePubsub();
pubsub.on("test", (data) => {
console.log(data);
});// in other .vue file / setup hook
pubsub.to("test", "Hello World!");
```### Using with Typescript
You can declare custom channel types by:
```typescript
declare module "vue-pubsub" {
interface Channels {
test: string;
}
}
```> Vue inject() and provide() do not support generic types in same context. Better suggestions for this are welcome.