[GH-ISSUE #2] Nice to have: check if changes were made in proxy transaction #1

Closed
opened 2026-05-23 08:36:09 -06:00 by gitea-mirror · 1 comment
Owner

Originally created by @appy-one on GitHub (Feb 26, 2021).
Original GitHub issue: https://github.com/appy-one/acebase-core/issues/2

Originally assigned to: @appy-one on GitHub.

When binding a proxied value to Angular inputs with ngModel but don't want the user inputs to be saved to the db immediately, one could use a proxy transaction that can be committed or rolled back based on the user's decision to save or cancel their edits. It is currently not possible however to query the transaction if any changes were made - which would enable asking the user if they want to save their changes.

Imagine doing this in ngOnInit:

const proxy = await db.ref('contacts/contact1').proxy({});
this.contact = proxy.value;
this.tx = contact.startTransaction();

Then imagine Angular doing this while the user edits the form:

this.contact.name = 'Ewout';
this.contact.country = 'NL';

Now, the user exits the form without saving:

// Should we...
this.tx.rollback();
// Or...
this.tx.commit();

Nice to have:

let save = false;
if (this.tx.hasMutations) { // <-- this
   save = await askUserIfTheyWantToSave();
}
if (save) {
   await this.tx.commit();
}
else {
  await this.tx.rollback();
}

I am aware it is possible to use an Angular FormGroup instead and checking form.dirty. However, when not using Angular, this is still nice to have for situations where one can't be sure if changes to the data were made or not.

Originally created by @appy-one on GitHub (Feb 26, 2021). Original GitHub issue: https://github.com/appy-one/acebase-core/issues/2 Originally assigned to: @appy-one on GitHub. When binding a proxied value to Angular inputs with ngModel but don't want the user inputs to be saved to the db immediately, one could use a proxy transaction that can be committed or rolled back based on the user's decision to save or cancel their edits. It is currently not possible however to query the transaction if any changes were made - which would enable asking the user if they want to save their changes. Imagine doing this in ngOnInit: ```js const proxy = await db.ref('contacts/contact1').proxy({}); this.contact = proxy.value; this.tx = contact.startTransaction(); ``` Then imagine Angular doing this while the user edits the form: ```js this.contact.name = 'Ewout'; this.contact.country = 'NL'; ``` Now, the user exits the form without saving: ```js // Should we... this.tx.rollback(); // Or... this.tx.commit(); ``` Nice to have: ```js let save = false; if (this.tx.hasMutations) { // <-- this save = await askUserIfTheyWantToSave(); } if (save) { await this.tx.commit(); } else { await this.tx.rollback(); } ``` I am aware it is possible to use an Angular ```FormGroup``` instead and checking ```form.dirty```. However, when not using Angular, this is still nice to have for situations where one can't be sure if changes to the data were made or not.
gitea-mirror added the
enhancement
live data proxy
labels 2026-05-23 08:36:09 -06:00
Author
Owner

@appy-one commented on GitHub (Feb 26, 2021):

Published with v1.1.0:

  • tx.hasMutations: whether there are pending mutations
  • tx.mutations: the actual pending mutations to be committed/rolled back
<!-- gh-comment-id:786765515 --> @appy-one commented on GitHub (Feb 26, 2021): Published with v1.1.0: * ```tx.hasMutations```: whether there are pending mutations * ```tx.mutations```: the actual pending mutations to be committed/rolled back
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/acebase-core#1
No description provided.