Update client library to handle async enrichment

This commit is contained in:
Andrew Kingston 2021-01-20 13:49:41 +00:00
parent ce5ab5482b
commit 976517e028
1 changed files with 10 additions and 2 deletions

View File

@ -16,11 +16,14 @@
const componentStore = writable({}) const componentStore = writable({})
setContext("component", componentStore) setContext("component", componentStore)
// Enrich component props
let enrichedProps
$: enrichComponentProps(definition, $dataContext, $bindingStore)
// Extract component definition info // Extract component definition info
$: constructor = getComponentConstructor(definition._component) $: constructor = getComponentConstructor(definition._component)
$: children = definition._children $: children = definition._children
$: id = definition._id $: id = definition._id
$: enrichedProps = enrichProps(definition, $dataContext, $bindingStore)
$: styles = definition._styles $: styles = definition._styles
// Allow component selection in the builder preview if we're previewing a // Allow component selection in the builder preview if we're previewing a
@ -38,6 +41,11 @@
return name === "screenslot" ? Router : ComponentLibrary[name] return name === "screenslot" ? Router : ComponentLibrary[name]
} }
// Enriches any string component props using handlebars
const enrichComponentProps = async (definition, context, bindingStore) => {
enrichedProps = await enrichProps(definition, context, bindingStore)
}
// Returns a unique key to let svelte know when to remount components. // Returns a unique key to let svelte know when to remount components.
// If a component is selected we want to remount it every time any props // If a component is selected we want to remount it every time any props
// change. // change.
@ -47,7 +55,7 @@
} }
</script> </script>
{#if constructor} {#if constructor && enrichedProps}
<svelte:component this={constructor} {...enrichedProps}> <svelte:component this={constructor} {...enrichedProps}>
{#if children && children.length} {#if children && children.length}
{#each children as child (getChildKey(child._id))} {#each children as child (getChildKey(child._id))}