Skip to content

Instantly share code, notes, and snippets.

View tachibana-shin's full-sized avatar
🏠
Working from home

Tachibana Shin tachibana-shin

🏠
Working from home
View GitHub Profile
@tachibana-shin
tachibana-shin / vue-event-bus.ts
Last active June 25, 2023 13:46
Event bus for vue and reactivity system
import { getCurrentScope, onScopeDispose } from "vue"
class EventBus<Events extends Record<string, unknown>> {
private readonly store = new Map<keyof Events, Set<(param: any) =>void>>()
constructor() {
this.on = this.on.bind(this)
this.off = this.off.bind(this)
this.emit = this.emit.bind(this)
}