1
0
Fork 0
mirror of synced 2024-09-19 10:48:30 +12:00
budibase/packages/standard-components/src/List.svelte

33 lines
655 B
Svelte
Raw Normal View History

2020-06-03 10:26:06 +12:00
<script>
import { getContext, onMount } from "svelte"
import { isEmpty } from "lodash/fp"
const { API, styleable, DataProvider } = getContext("sdk")
const component = getContext("component")
const dataContext = getContext("data")
2020-06-03 10:26:06 +12:00
export let datasource = []
2020-06-03 10:26:06 +12:00
2020-11-19 00:24:01 +13:00
let rows = []
2020-06-03 10:26:06 +12:00
2021-01-12 09:17:56 +13:00
$: datasource && fetchData()
async function fetchData() {
rows = await API.fetchDatasource(datasource, $dataContext)
}
onMount(async () => {
if (!isEmpty(datasource)) {
2021-01-12 09:17:56 +13:00
fetchData()
2020-06-03 10:26:06 +12:00
}
})
</script>
<div use:styleable={$component.styles}>
2020-11-19 00:24:01 +13:00
{#each rows as row}
<DataProvider {row}>
<slot />
</DataProvider>
{/each}
</div>