polarpress-pagebuilder/resources/js/components/EventBus.vue
Helge-Mikael Nordgård e15d3ae146
Some checks are pending
linter / quality (push) Waiting to run
tests / ci (push) Waiting to run
Transferred and translated the frontend code from L10 to L12
2025-05-05 19:01:27 +02:00

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>