diff --git a/src/Smartable/AsyncManager.tsx b/src/Smartable/AsyncManager.tsx index 947a5fb..20abffd 100644 --- a/src/Smartable/AsyncManager.tsx +++ b/src/Smartable/AsyncManager.tsx @@ -85,6 +85,12 @@ class AsyncManager protected promisedRowsCells: Partial>>[] = []; + /** + * Tells if rows are loaded or not. + * @protected + */ + protected rowsLoaded: boolean = false; + /** * Rows data. * @protected @@ -109,6 +115,7 @@ class AsyncManager */ handle(data: SmartableData): void { + this.rowsLoaded = false; this.promisedData.refresh(data); } @@ -125,6 +132,7 @@ class AsyncManager // Initialize rows data and cells definitions. this.rowsData = []; this.cellsDefinitions = []; + this.rowsLoaded = true; for (const [rowId, rowDefinition] of rowsDefinitions.entries()) { // Get row data of each row. @@ -218,20 +226,21 @@ class AsyncManager { if (!( // Checking that there is at least one changed value. - this.rowsData.length > 0 && this.cellsDefinitions.some((rowCells) => ( + this.rowsData.length > 0 || this.cellsDefinitions.some((rowCells) => ( Object.keys(rowCells).length > 0 )) + || ((this.rowsLoaded && !this.currentDataState.rows) || (!this.rowsLoaded && this.currentDataState.rows)) )) // Nothing has changed. return; // Initialize new data. const newData = { - rows: [ + rows: !this.rowsLoaded ? undefined : [ ...(this.currentDataState?.rows ?? []) ], }; - for (const [rowId, newRow] of this.rowsData.entries()) + for (const [rowId, newRow] of this.rowsData?.entries()) { // Update value of each new row. newData.rows[rowId] = { element: newRow.element, @@ -240,7 +249,7 @@ class AsyncManager }; } - for (const [rowId, rowCells] of this.cellsDefinitions.entries()) + for (const [rowId, rowCells] of this.cellsDefinitions?.entries()) { // Update cells of each changed row. newData.rows[rowId] = { ...newData.rows[rowId],