2020-06-03 00:26:06 +02:00
|
|
|
<script>
|
2020-11-18 20:18:18 +01:00
|
|
|
import { getContext, onMount } from "svelte"
|
2020-08-26 18:03:30 +02:00
|
|
|
import { isEmpty } from "lodash/fp"
|
2020-11-18 20:18:18 +01:00
|
|
|
|
2020-11-20 10:50:10 +01:00
|
|
|
const { API, styleable, DataProvider } = getContext("sdk")
|
2020-11-24 12:02:10 +01:00
|
|
|
const component = getContext("component")
|
2021-01-19 15:11:21 +01:00
|
|
|
console.log($component)
|
2020-11-25 19:43:58 +01:00
|
|
|
const dataContext = getContext("data")
|
2020-06-03 00:26:06 +02:00
|
|
|
|
2020-08-26 18:03:30 +02:00
|
|
|
export let datasource = []
|
2020-06-03 00:26:06 +02:00
|
|
|
|
2020-11-18 12:24:01 +01:00
|
|
|
let rows = []
|
2020-06-03 00:26:06 +02:00
|
|
|
|
2021-01-11 21:17:56 +01:00
|
|
|
$: datasource && fetchData()
|
|
|
|
|
|
|
|
async function fetchData() {
|
|
|
|
rows = await API.fetchDatasource(datasource, $dataContext)
|
|
|
|
}
|
|
|
|
|
2020-08-26 18:03:30 +02:00
|
|
|
onMount(async () => {
|
|
|
|
if (!isEmpty(datasource)) {
|
2021-01-11 21:17:56 +01:00
|
|
|
fetchData()
|
2020-06-03 00:26:06 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
2020-11-24 12:02:10 +01:00
|
|
|
<div use:styleable={$component.styles}>
|
2021-01-19 15:11:21 +01:00
|
|
|
{#if rows.length > 0}
|
|
|
|
{#each rows as row}
|
|
|
|
<DataProvider {row}>
|
|
|
|
<slot />
|
|
|
|
</DataProvider>
|
|
|
|
{/each}
|
|
|
|
{:else}
|
|
|
|
<p>Feed me some data</p>
|
|
|
|
{/if}
|
2020-11-18 12:24:01 +01:00
|
|
|
</div>
|
2021-01-19 15:11:21 +01:00
|
|
|
|
|
|
|
<style>
|
|
|
|
p {
|
|
|
|
display: grid;
|
|
|
|
place-items: center;
|
|
|
|
background: #f5f5f5;
|
|
|
|
border: #ccc 1px solid;
|
|
|
|
padding: var(--spacing-m);
|
|
|
|
}
|
|
|
|
</style>
|