Loading is disappearing and come back

sorry for so many repies. i think i should probably summarize since ive given you so many different ways to do 1 thing, and each with their pros and cons.

lets start witht the down and dirty itll work one:

await query2.trigger();
await query3.trigger();
await isAnythingLoading.setValue(false);

why is this the down and dirty way? well it works, but its possible to see little or 0-ish i.prove t in speed.
PROS:

  • easy to understand
  • easy to debug and either rule rule out the code as causing a problem or not
  • easy to maintain. the most expensive part of software development is last part, maintenance
  • its safe, itll fix the loading error u had

CONS:

  • This is the same as using the Successful event handlers and doing everything manually. the only diff is you're bypassing some the Retool overhead for a slight speed increase. it could also be worse. using the HI to set the Success event handler
  • its not flexible and so requires a try/catch
const queryList = [];
queryList.push(query2.trigger({
  onSuccess: function(data) {
    query3.trigger(); //needs results from query2
    query4.trigger(); //needs results from query2 but doesn't care about query3
  },
  onFailure: function(data) {
    //we need to do something specific if query2 fails.
  }
}));

//query5 doesn't care about query1,2 or 3.
queryList.push(query5.trigger({
  onSuccess: function(data) {
    query6.trigger(); //needs results from query5 but doesn't care about 1,2 or 3 either.
  }
}));

Promise.all(queryList).then(() => {
  //all queries are successful
  isAnythingLoading.setValue(false);
}.catch((error) => {
  //at least one promise failed, we can handle that here
  console.log(error);
});

PROS;

  • it'll be faster
  • it'is safe, the loading thing will be fixed
1 Like