Disregard block components from ejection which are unmounted during parent blocks lifecycles
This commit is contained in:
parent
e9c6aa2593
commit
7b80dabfe2
|
@ -9,7 +9,7 @@
|
|||
let structureLookupMap = {}
|
||||
|
||||
const registerBlockComponent = (id, order, parentId, instance) => {
|
||||
// Ensure child array exists
|
||||
// Ensure child map exists
|
||||
if (!structureLookupMap[parentId]) {
|
||||
structureLookupMap[parentId] = {}
|
||||
}
|
||||
|
@ -18,6 +18,14 @@
|
|||
structureLookupMap[parentId][order] = instance
|
||||
}
|
||||
|
||||
const unregisterBlockComponent = (order, parentId) => {
|
||||
// Ensure child map exists
|
||||
if (!structureLookupMap[parentId]) {
|
||||
return
|
||||
}
|
||||
delete structureLookupMap[parentId][order]
|
||||
}
|
||||
|
||||
const eject = () => {
|
||||
// Start the new structure with the root component
|
||||
let definition = structureLookupMap[$component.id][0]
|
||||
|
@ -73,6 +81,7 @@
|
|||
// We register block components with their raw props so that we can eject
|
||||
// blocks later on
|
||||
registerComponent: registerBlockComponent,
|
||||
unregisterComponent: unregisterBlockComponent,
|
||||
})
|
||||
|
||||
onMount(() => {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<script>
|
||||
import { getContext } from "svelte"
|
||||
import { getContext, onDestroy } from "svelte"
|
||||
import { generate } from "shortid"
|
||||
import { builderStore } from "../stores/builder.js"
|
||||
import Component from "components/Component.svelte"
|
||||
|
@ -41,6 +41,12 @@
|
|||
block.registerComponent(id, order ?? 0, $component?.id, instance)
|
||||
}
|
||||
}
|
||||
|
||||
onDestroy(() => {
|
||||
if ($builderStore.inBuilder) {
|
||||
block.unregisterComponent(order ?? 0, $component?.id)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<Component {instance} isBlock>
|
||||
|
|
Loading…
Reference in New Issue