This commit is contained in:
Jan Prochazka
2021-02-25 09:12:01 +01:00
parent fc333167ac
commit ef910f43a6
4 changed files with 31 additions and 34 deletions

View File

@@ -155,10 +155,10 @@ export default class ChangeSetGrider extends Grider {
return this.insertedRows.length > 0; return this.insertedRows.length > 0;
} }
static factory({ sourceRows, changeSetState, dispatchChangeSet, display }): ChangeSetGrider { // static factory({ sourceRows, changeSetState, dispatchChangeSet, display }): ChangeSetGrider {
return new ChangeSetGrider(sourceRows, changeSetState, dispatchChangeSet, display); // return new ChangeSetGrider(sourceRows, changeSetState, dispatchChangeSet, display);
} // }
static factoryDeps({ sourceRows, changeSetState, dispatchChangeSet, display }) { // static factoryDeps({ sourceRows, changeSetState, dispatchChangeSet, display }) {
return [sourceRows, changeSetState ? changeSetState.value : null, dispatchChangeSet, display]; // return [sourceRows, changeSetState ? changeSetState.value : null, dispatchChangeSet, display];
} // }
} }

View File

@@ -32,7 +32,7 @@
export let isInserted = false; export let isInserted = false;
export let isDeleted = false; export let isDeleted = false;
$: value = rowData[col.uniqueName]; $: value = (rowData || {})[col.uniqueName];
</script> </script>
<td <td

View File

@@ -4,40 +4,39 @@
export let loadDataPage; export let loadDataPage;
export let dataPageAvailable; export let dataPageAvailable;
export let loadRowCount; export let loadRowCount;
export let griderFactory; export let grider;
// export let griderFactory;
let loadProps = { export let loadedRows = [];
isLoading: false, let isLoading = false;
loadedRows: [], let isLoadedAll = false;
isLoadedAll: false, let loadedTime = new Date().getTime();
loadedTime: new Date().getTime(), let allRowCount = null;
allRowCount: null, let errorMessage = null;
errorMessage: null, let loadNextDataToken = 0;
loadNextDataToken: 0,
};
async function loadNextData() { async function loadNextData() {
if (loadProps.isLoading) return; if (isLoading) return;
loadProps.isLoading = true; isLoading = true;
const loadStart = new Date().getTime(); const loadStart = new Date().getTime();
// loadedTimeRef.current = loadStart; // loadedTimeRef.current = loadStart;
const nextRows = await loadDataPage($$props, loadProps.loadedRows.length, 100); const nextRows = await loadDataPage($$props, loadedRows.length, 100);
// if (loadedTimeRef.current !== loadStart) { // if (loadedTimeRef.current !== loadStart) {
// // new load was dispatched // // new load was dispatched
// return; // return;
// } // }
loadProps.isLoading = false; isLoading = false;
if (nextRows.errorMessage) { if (nextRows.errorMessage) {
loadProps.errorMessage = nextRows.errorMessage; errorMessage = nextRows.errorMessage;
} else { } else {
// if (allRowCount == null) handleLoadRowCount(); // if (allRowCount == null) handleLoadRowCount();
loadProps.loadedRows = [...loadProps.loadedRows, ...nextRows]; loadedRows = [loadedRows, ...nextRows];
loadProps.isLoadedAll = nextRows.length === 0; isLoadedAll = nextRows.length === 0;
// const loadedInfo = { // const loadedInfo = {
// loadedRows: [...loadedRows, ...nextRows], // loadedRows: [...loadedRows, ...nextRows],
// loadedTime, // loadedTime,
@@ -52,11 +51,11 @@
} }
} }
$: griderProps = { ...$$props, sourceRows: loadProps.loadedRows }; // $: griderProps = { ...$$props, sourceRows: loadProps.loadedRows };
$: grider = griderFactory(griderProps); // $: grider = griderFactory(griderProps);
const handleLoadNextData = () => { const handleLoadNextData = () => {
if (!loadProps.isLoadedAll && !loadProps.errorMessage && !grider.disableLoadNextPage) { if (!isLoadedAll && !errorMessage && !grider.disableLoadNextPage) {
if (dataPageAvailable($$props)) { if (dataPageAvailable($$props)) {
// If not, callbacks to load missing metadata are dispatched // If not, callbacks to load missing metadata are dispatched
loadNextData(); loadNextData();

View File

@@ -50,16 +50,14 @@
import LoadingDataGridCore from './LoadingDataGridCore.svelte'; import LoadingDataGridCore from './LoadingDataGridCore.svelte';
export let conid; export let conid;
export let display;
export let database; export let database;
export let schemaName; export let schemaName;
export let pureName; export let pureName;
export let config; export let config;
let loadedRows = [];
$: grider = new ChangeSetGrider(loadedRows, null, null, display);
</script> </script>
<LoadingDataGridCore <LoadingDataGridCore {...$$props} {loadDataPage} {dataPageAvailable} {loadRowCount} bind:loadedRows {grider} />
{...$$props}
{loadDataPage}
{dataPageAvailable}
{loadRowCount}
griderFactory={ChangeSetGrider.factory}
/>