Skip to content

Commit

Permalink
feat(reference): Add hasUnprocessedChanges_ flag to CollectionReferen…
Browse files Browse the repository at this point in the history
…ce and DocumentReference
  • Loading branch information
alimd committed Dec 29, 2023
1 parent 68695a9 commit dff3553
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/reference/src/collection-reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ export class CollectionReference<TItem extends Dictionary = Dictionary> {
*/
private async updated__(id?: string | number): Promise<void> {
this.logger__.logMethodArgs?.('updated__', {delayed: this.updateDelayed__});

this.hasUnprocessedChanges_ = true;
this.updateMeta__(id);

Expand Down
13 changes: 12 additions & 1 deletion packages/reference/src/document-reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ export class DocumentReference<TDoc extends Dictionary = Dictionary> {
*/
readonly path: string;

/**
* Indicates whether the collection has unsaved changes.
*/
hasUnprocessedChanges_ = false;

/**
* Logger instance for this document.
*/
Expand Down Expand Up @@ -259,6 +264,9 @@ export class DocumentReference<TDoc extends Dictionary = Dictionary> {
*/
private async updated__(): Promise<void> {
this.logger__.logMethodArgs?.('updated__', {delayed: this.updateDelayed__});

this.hasUnprocessedChanges_ = true;

if (this.updateDelayed__ === true) return;
// else

Expand All @@ -269,7 +277,10 @@ export class DocumentReference<TDoc extends Dictionary = Dictionary> {
}

this.updateMeta__();
this.updatedCallback__.call(null, this);
if (this.hasUnprocessedChanges_ === true) {
this.hasUnprocessedChanges_ = false;
this.updatedCallback__.call(null, this);
}
}

/**
Expand Down

0 comments on commit dff3553

Please sign in to comment.