22 lines
524 B
Vue
22 lines
524 B
Vue
<script>
|
|
// This bus handles generic events from components
|
|
import { reactive, watchEffect } from 'vue';
|
|
|
|
export const state = reactive({
|
|
event: null,
|
|
payload: null,
|
|
});
|
|
|
|
export function emit(eventName, payload) {
|
|
state.event = eventName;
|
|
state.payload = payload;
|
|
}
|
|
|
|
export function on(eventName, callback) {
|
|
watchEffect(() => {
|
|
if (state.event === eventName) {
|
|
callback(state.payload);
|
|
}
|
|
});
|
|
}
|
|
</script> |