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,33 +539,30 @@
} }
} }
// 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, {
) { component: instance._component,
componentStore.actions.registerInstance(id, { getSettings: () => cachedSettings,
component: instance._component, getRawSettings: () => ({ ...staticSettings, ...dynamicSettings }),
getSettings: () => cachedSettings, getDataContext: () => get(context),
getRawSettings: () => ({ ...staticSettings, ...dynamicSettings }), reload: () => initialise(instance, true),
getDataContext: () => get(context), setEphemeralStyles: styles => (ephemeralStyles = styles),
reload: () => initialise(instance, true), state: store,
setEphemeralStyles: styles => (ephemeralStyles = styles), })
state: store, }
}) return () => {
if (componentStore.actions.isComponentRegistered(id)) {
componentStore.actions.unregisterInstance(id)
}
}
} }
}) })
// Observe changes to context
onMount(() => context.actions.observeChanges(handleContextChange)) onMount(() => context.actions.observeChanges(handleContextChange))
onDestroy(() => {
if (
$appStore.isDevApp &&
componentStore.actions.isComponentRegistered(id)
) {
componentStore.actions.unregisterInstance(id)
}
})
</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"