I have the following vivious cirle and wanted to consult with you as maybe you will know good solution for that. Namely, how to stop callback if it’s triggered indirectly?
A bit of background:
- In my app I have a checkbox (toggle button)
- Its status is set when loading the page: if there is record in database then ON, if no record then OFF
- Toggle has its own callback: if user switched toggle to ON then add a record, if switched to OFF then remove the record
So what happens it that when page is loaded: code is checking in the database if record exists > yes, so switch toggle to ON > because it was switched to ON add record to the database. Sam happens for OFF, but with delete record effect.
I want to avoid unnecessary traffic on db, so wanted to check if there is any way to break such relationship? Basically initial setting of the checkbox should stop callback from being triggered.