sequentially perform actions that require source retrieval at same time
bmhardy opened this issue · 2 comments
Can we have the ability to sequentially perform actions that require source retrieval at same time?
class SearchStore {
constructor() {
this.state = { value: '' };
this.registerAsync(SearchSource);
}
onSearch() {
if (!this.getInstance().isLoading()) {
this.getInstance().performSearch();
}
}
}
Note the isLoading call. What can I do when I have multiple components relying on the same store that want to call onSearch (via an action) at (relatively) the same time. The second call will come while the store "isLoading" the results for the first call, and thus the second call will do nothing? Is there an Alt way that I can queue up multiple calls while one is taking place?
@bmhardy i haven't seen any out of the box functionality for this, but you could build the functionality with a concept of a QueueStore
that can act as your queue of asynchronous calls you need to make.
You probably want to move the "should make async call" logic into your source as part of your shouldFetch
function. And in there you could trigger actions to add to the queue if the SearchStore
is loading. Once the store is done loading, you could work off your queue until it's empty.
Hope that was somewhat helpful.