I have a couple of global modals that are reused across pages, for example an edit contact modal that can be used in various pages that have contacts. After editing the contact I would like the local data to refresh. Both the modal and the query are in global scope so post Contact and modal contact are both global. I have a local table I need to refresh and Iβm wondering what the best pattern is to refresh a local table from a global modal / query.
Claude came up with the below, but I thought there might be a more elegant solution that doesnβt involve polling? Is there a way to monitor a variable to that when it changes it triggers an event?
The Automatic watch is greyed out:
**Local Global trigger Pattern
Global setup:**
-
A global variable called
varRefreshTriggerwith a default value ofnull -
A global variable called
varPageNamethat is set to the current page name before the modal is opened -
In the global query's
onSuccesshandler, set the trigger like this:
javascript
varRefreshTrigger.setValue({
page: varPageName.value,
timestamp: Date.now()
});
Local page setup:
-
Each page has a local JS query named
[pageName]Watcher(e.g.tasksWatcher,sequencesWatcher) that acts as a refresh watcher -
The query runs on a 1000ms polling interval (set via "Run this query periodically" in the Advanced tab) since Retool does not reliably detect global variable dependencies in JS queries automatically
-
The query checks the trigger and fires the local refresh query if the page name matches:
javascript
const trigger = varRefreshTrigger.value;
if (trigger?.page === "[PageName]") {
varRefreshTrigger.setValue(null);
localQuery.trigger();
}
When I describe a new page that needs this behavior, generate the watcher query code and remind me to enable periodic polling at 1000ms in the Advanced tab.
