<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>