Commit ad648947 authored by Michael Underwood's avatar Michael Underwood
Browse files

Rework tooltip to use explicit injections

parent 77f8a108
Loading
Loading
Loading
Loading
+4 −10
Original line number Diff line number Diff line
@@ -10,16 +10,10 @@ export default {
  name: "LTooltip",
  props,
  setup(props, context) {
    const leafletRef = ref({});
    const root = ref(null);

    const lMethods = inject("leafLetMethods");
    const { options, methods } = tooltipSetup(
      props,
      leafletRef,
      context,
      lMethods
    );
    const leafletRef = ref({});
    const { options, methods } = tooltipSetup(props, leafletRef);
    const bindTooltip = inject("bindTooltip");

    onMounted(async () => {
      const { tooltip, DomEvent, setOptions } = await import(
@@ -32,7 +26,7 @@ export default {
      const listeners = remapEvents(context.attrs);
      DomEvent.on(leafletRef.value, listeners);
      leafletRef.value.setContent(props.content || root.value);
      lMethods.bindTooltip({ mapObject: leafletRef.value });
      bindTooltip({ mapObject: leafletRef.value });
    });
    return { root };
  },
+2 −4
Original line number Diff line number Diff line
@@ -85,10 +85,8 @@ export const setup = (props, leafletRef, context) => {
    },
  };

  provide("leafLetMethods", {
    bindTooltip: methods.bindTooltip,
    unbindTooltip: methods.unbindTooltip,
  });
  provide("bindTooltip", methods.bindTooltip);
  provide("unbindTooltip", methods.unbindTooltip);

  onUnmounted(() => {
    methods.unbindPopup();
+4 −3
Original line number Diff line number Diff line
import { onBeforeUnmount } from "vue";
import { inject, onBeforeUnmount } from "vue";
import { props as popperProps, setup as popperSetup } from "./popper";

export const props = {
  ...popperProps,
};

export const setup = (props, leafletRef, context, lMethods) => {
export const setup = (props, leafletRef) => {
  const { options, methods } = popperSetup(props, leafletRef);
  const unbindTooltip = inject("unbindTooltip");

  onBeforeUnmount(() => {
    lMethods.unbindTooltip();
    unbindTooltip();
  });

  return { options, methods };