From 863c70222b9252fe8b9754da987411e28b6e3f1b Mon Sep 17 00:00:00 2001 From: thepaperpilot <thepaperpilot@gmail.com> Date: Fri, 8 Jul 2022 08:44:01 -0500 Subject: [PATCH] Better handling of provide failing Was having trouble with Vite HMR --- src/components/Node.vue | 6 ++++-- src/features/links/Links.vue | 7 +++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/components/Node.vue b/src/components/Node.vue index c844c26..e1686e3 100644 --- a/src/components/Node.vue +++ b/src/components/Node.vue @@ -9,8 +9,10 @@ import { computed, inject, onUnmounted, ref, toRefs, unref, watch } from "vue"; const _props = defineProps<{ id: string }>(); const props = toRefs(_props); -const register = inject(RegisterNodeInjectionKey); -const unregister = inject(UnregisterNodeInjectionKey); +// eslint-disable-next-line @typescript-eslint/no-empty-function +const register = inject(RegisterNodeInjectionKey, () => {}); +// eslint-disable-next-line @typescript-eslint/no-empty-function +const unregister = inject(UnregisterNodeInjectionKey, () => {}); const node = ref<HTMLElement | null>(null); const parentNode = computed(() => node.value && node.value.parentElement); diff --git a/src/features/links/Links.vue b/src/features/links/Links.vue index b9117c3..bbf4740 100644 --- a/src/features/links/Links.vue +++ b/src/features/links/Links.vue @@ -14,6 +14,7 @@ <script setup lang="ts"> import type { Link } from "features/links/links"; +import type { FeatureNode } from "game/layers"; import { BoundsInjectionKey, NodesInjectionKey } from "game/layers"; import { computed, inject, ref, toRef, watch } from "vue"; import LinkVue from "./Link.vue"; @@ -23,10 +24,8 @@ const links = toRef(_props, "links"); const resizeListener = ref<Element | null>(null); -// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -const nodes = inject(NodesInjectionKey)!; -// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -const outerBoundingRect = inject(BoundsInjectionKey)!; +const nodes = inject(NodesInjectionKey, ref<Record<string, FeatureNode | undefined>>({})); +const outerBoundingRect = inject(BoundsInjectionKey, ref<DOMRect | undefined>(undefined)); const boundingRect = ref<DOMRect | undefined>(undefined); watch( [outerBoundingRect],