vue-hooks-plus
Version: 
Vue hooks library
20 lines (19 loc) • 648 B
JavaScript
import { ref, computed, watchEffect } from "vue";
import { eventEmitterOverall, EventEmitter } from "./event";
function useEventEmitter(options) {
  const eventRef = ref();
  const eventEmitterOptions = computed(() => options != null ? options : { global: false });
  if (!eventRef.value) {
    eventRef.value = eventEmitterOptions.value.global ? eventRef.value = eventEmitterOverall : eventRef.value = new EventEmitter();
  }
  watchEffect((onInvalidate) => {
    onInvalidate(() => {
      var _a;
      return (_a = eventRef.value) == null ? void 0 : _a.clear();
    });
  });
  return eventRef.value;
}
export {
  useEventEmitter as default
};