This commit is contained in:
Andrew Kingston 2023-09-15 08:02:14 +01:00
parent 49948df9cd
commit 46a9f98fe5
2 changed files with 21 additions and 25 deletions

View File

@ -9,7 +9,7 @@
</script> </script>
<script> <script>
import { getContext, setContext, onMount, onDestroy } from "svelte" import { getContext, setContext, onMount } from "svelte"
import { writable, get } from "svelte/store" import { writable, get } from "svelte/store"
import { import {
enrichProps, enrichProps,
@ -86,7 +86,6 @@
// Keep track of stringified representations of context and instance // Keep track of stringified representations of context and instance
// to avoid enriching bindings as much as possible // to avoid enriching bindings as much as possible
let lastContextKey
let lastInstanceKey let lastInstanceKey
// Visibility flag used by conditional UI // Visibility flag used by conditional UI
@ -540,11 +539,10 @@
} }
} }
// Register an unregister component instance
onMount(() => { onMount(() => {
if ( if ($appStore.isDevApp) {
$appStore.isDevApp && if (!componentStore.actions.isComponentRegistered(id)) {
!componentStore.actions.isComponentRegistered(id)
) {
componentStore.actions.registerInstance(id, { componentStore.actions.registerInstance(id, {
component: instance._component, component: instance._component,
getSettings: () => cachedSettings, getSettings: () => cachedSettings,
@ -555,18 +553,16 @@
state: store, state: store,
}) })
} }
}) return () => {
if (componentStore.actions.isComponentRegistered(id)) {
onMount(() => context.actions.observeChanges(handleContextChange))
onDestroy(() => {
if (
$appStore.isDevApp &&
componentStore.actions.isComponentRegistered(id)
) {
componentStore.actions.unregisterInstance(id) componentStore.actions.unregisterInstance(id)
} }
}
}
}) })
// Observe changes to context
onMount(() => context.actions.observeChanges(handleContextChange))
</script> </script>
{#if constructor && initialSettings && (visible || inSelectedPath) && !builderHidden} {#if constructor && initialSettings && (visible || inSelectedPath) && !builderHidden}

View File

@ -1,5 +1,5 @@
<script> <script>
import { dayjs } from "dayjs" import dayjs from "dayjs"
import { CoreDatePicker, Icon } from "@budibase/bbui" import { CoreDatePicker, Icon } from "@budibase/bbui"
import { onMount } from "svelte" import { onMount } from "svelte"