lundi 15 juin 2020

Execute an instruction after or before another instruction according to a boolean

I have code like this:

if (!cached) {
  // execute and wait for server request
}

store.subscribe(state => {
  // some code
});

if (cached) {
  // execute and wait for server request (same code line as above)
}

store.set(data)

cached = true

If cached is false, wait for data from the server before subscribing to the store. If cached is true, subscribe immediately to the store and then execute the request.

I think this code can improve but I can't think of a solution.

Aucun commentaire:

Enregistrer un commentaire