Simplify some block logic

This commit is contained in:
Andrew Kingston 2021-11-02 12:58:38 +00:00
parent e43aba075e
commit 76c0f24977
2 changed files with 10 additions and 16 deletions

View File

@ -7,9 +7,7 @@
// We need to set a block context to know we're inside a block, but also // We need to set a block context to know we're inside a block, but also
// to be able to reference the actual component ID of the block from // to be able to reference the actual component ID of the block from
// any depth // any depth
setContext("block", { setContext("block", { id: $component.id })
id: $component.id,
})
</script> </script>
<div use:styleable={$component.styles}> <div use:styleable={$component.styles}>

View File

@ -14,22 +14,18 @@
const block = getContext("block") const block = getContext("block")
const rand = generate() const rand = generate()
$: id = block.id + rand
$: instance = createInstance(type, props, id)
// Create a fake component instance so that we can use the core Component // Create a fake component instance so that we can use the core Component
// to render this part of the block, taking advantage of binding enrichment // to render this part of the block, taking advantage of binding enrichment
const createInstance = (type, props, id) => { $: id = block.id + rand
return { $: instance = {
_component: `@budibase/standard-components/${type}`, _component: `@budibase/standard-components/${type}`,
_id: id, _id: id,
_styles: { _styles: {
normal: { normal: {
...styles, ...styles,
},
}, },
...props, },
} ...props,
} }
</script> </script>