Commit 4826999a authored by Michael Underwood's avatar Michael Underwood
Browse files

WIP rework leaflet method provision. Remove console logs.

parent d9cf01fc
Loading
Loading
Loading
Loading
+2 −7
Original line number Diff line number Diff line
@@ -11,9 +11,8 @@ import {
  propsBinder,
  debounce,
  resetWebpackIcon,
  generatePlaceholderMethods,
  provideLeafletMethods,
  updateLeafletMethod,
  provideLeafletPlaceholders,
} from "../utils.js";

export default {
@@ -164,15 +163,12 @@ export default {
      markerZoomAnimation: props.markerZoomAnimation,
    };

    const schematics = generatePlaceholderMethods([
    const schematics = provideLeafletPlaceholders([
      "addLayer",
      "removeLayer",
      "registerLayerControl",
    ]);

    console.log("Providing placeholder addLayer");
    provideLeafletMethods(schematics);

    const eventHandlers = {
      moveEndHandler() {
        /**
@@ -331,7 +327,6 @@ export default {
        },
      };

      console.log("Reassigning addLayer");
      updateLeafletMethod(schematics.addLayer, methods.addLayer);
      updateLeafletMethod(schematics.removeLayer, methods.removeLayer);
      updateLeafletMethod(
+2 −3
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ import {
  remapEvents,
  propsBinder,
  debounce,
  generatePlaceholderMethods,
  provideLeafletPlaceholders,
  injectLeafletMethod,
  updateLeafletMethod,
} from "../utils.js";
@@ -20,9 +20,8 @@ export default {
    const leafletRef = ref({});
    const ready = ref(false);

    const schematics = generatePlaceholderMethods(["latLng"]);
    const schematics = provideLeafletPlaceholders(["latLng"]);

    console.log("Injecting addLayer to LMarker");
    const addLayer = injectLeafletMethod("addLayer");
    const { options, methods } = markerSetup(
      props,
+0 −1
Original line number Diff line number Diff line
@@ -7,7 +7,6 @@ export default {
  props,
  setup(props, context) {
    const leafletRef = ref({});
    console.log("injecting addLayer to LTileLayer");
    const addLayer = injectLeafletMethod("addLayer");

    const { options, methods } = tileLayerSetup(props, leafletRef);
+12 −5
Original line number Diff line number Diff line
import { onUnmounted, provide } from "vue";
import { injectLeafletMethod } from "../utils";
import { onUnmounted } from "vue";
import {
  provideLeafletPlaceholders,
  injectLeafletMethod,
  updateLeafletMethod,
} from "../utils";

export const props = {
  pane: {
@@ -28,7 +32,6 @@ export const props = {
};

export const setup = (props, leafletRef, context) => {
  console.log("injecting addLayer to layer");
  const addLayer = injectLeafletMethod("addLayer");
  const removeLayer = injectLeafletMethod("removeLayer");
  const options = {
@@ -87,8 +90,12 @@ export const setup = (props, leafletRef, context) => {
    },
  };

  provide("bindTooltip", methods.bindTooltip);
  provide("unbindTooltip", methods.unbindTooltip);
  const schematics = provideLeafletPlaceholders([
    "bindTooltip",
    "unbindTooltip",
  ]);
  updateLeafletMethod(schematics.bindTooltip, methods.bindTooltip);
  updateLeafletMethod(schematics.unbindTooltip, methods.unbindTooltip);

  onUnmounted(() => {
    methods.unbindPopup();
+12 −11
Original line number Diff line number Diff line
@@ -71,19 +71,21 @@ export const resetWebpackIcon = (Icon) => {
  });
};

export const generatePlaceholderMethods = (methods) => {
  const base = {}; //reactive({});
  return methods.reduce((acc, curr) => {
    acc[curr] = ref(() =>
      console.warn(`Method ${curr} has been invoked without being replaced`)
export const provideLeafletPlaceholders = (methodNames) => {
  return methodNames.reduce((methods, methodName) => {
    methods[methodName] = ref(() =>
      console.warn(
        `Method ${methodName} has been invoked without being replaced`
      )
    );
    return acc;
  }, base);
    provide(methodName, methods[methodName]);
    return methods;
  }, {});
};

export const provideLeafletMethods = (obj) => {
  for (const key in obj) {
    provide(key, obj[key]);
export const provideLeafletMethods = (methods) => {
  for (const methodName in methods) {
    provide(methodName, methods[methodName]);
  }
};

@@ -93,7 +95,6 @@ export const updateLeafletMethod = (methodRef, updateMethod) => {

export const injectLeafletMethod = (methodName) => {
  const method = inject(methodName);
  console.log("injected method", method);
  return (
    (method && method.value) ||
    (() => console.warn(`"${methodName}" not provided as Leaflet method.`))