budibase/packages/standard-components/src/List.svelte

31 lines
792 B
Svelte
Raw Normal View History

2020-06-03 00:26:06 +02:00
<script>
import { onMount, setContext } from "svelte"
import {
fetchDatasource,
createDataProviderContext,
fetchTableDefinition,
ContextTypes,
} from "@budibase/component-sdk"
import { isEmpty } from "lodash/fp"
2020-06-03 00:26:06 +02:00
export let datasource = []
2020-06-03 00:26:06 +02:00
let target
const dataProviderContext = createDataProviderContext()
setContext(ContextTypes.DataProvider, dataProviderContext)
2020-06-03 00:26:06 +02:00
onMount(async () => {
if (!isEmpty(datasource)) {
const rows = await fetchDatasource(datasource)
dataProviderContext.actions.setRows(rows)
if (datasource.tableId) {
const tableDefinition = await fetchTableDefinition(datasource.tableId)
dataProviderContext.actions.setTable(tableDefinition)
}
2020-06-03 00:26:06 +02:00
}
})
</script>
2020-07-07 22:29:20 +02:00
<section bind:this={target} />