Skip to content

Commit

Permalink
add datasource api flush method
Browse files Browse the repository at this point in the history
  • Loading branch information
radubrehar committed Sep 21, 2024
1 parent 9a87545 commit 25505f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion source/src/components/DataSource/getDataSourceApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,16 @@ class DataSourceApiImpl<T> implements DataSourceApi<T> {
this.actions.cache = cache;
}

flush() {
return this.commit();
}

commit() {
this.commitOperations(this.pendingOperations);
this.pendingOperations.length = 0;

if (this.pendingPromise && this.resolvePendingPromise) {
const pendingPromise = this.pendingPromise;
if (pendingPromise && this.resolvePendingPromise) {
const resolve = this.resolvePendingPromise;
// let's resolve the promise in the next frame
// so we give the DataSource reducer the chance to pick up the commited operations
Expand All @@ -175,6 +180,8 @@ class DataSourceApiImpl<T> implements DataSourceApi<T> {
this.pendingPromise = null;
this.resolvePendingPromise = null;
}

return pendingPromise || Promise.resolve(true);
}

getRowInfoArray = () => {
Expand Down
2 changes: 2 additions & 0 deletions source/src/components/DataSource/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ export interface DataSourceApi<T> {
options?: DataSourceCRUDParam,
): Promise<any>;

flush(): Promise<any>;

removeDataByPrimaryKey(id: any, options?: DataSourceCRUDParam): Promise<any>;
removeDataArrayByPrimaryKeys(
id: any[],
Expand Down

0 comments on commit 25505f1

Please sign in to comment.