0

I'm having trouble sequencing tiers of computation in my app. I'm using an Akita entity store to manage state and then observing changes and piping them through observables to generate the UI state. The overall flow is:

EntityStore.selectAll()
  -> pluck A  \     /  combineLatest(A, B) -> map Q
  -> pluck B  |    |   combineLatest(A, C) -> map R
  -> pluck C  |-> -|   combineLatest(B, E) -> map S
     ...      |    |   ...
  -> pluck N  /     \  combineLatest(C, D) -> map Z

(Assume distinctUntilChanged after each operator).

How do I ensure that A..N are calculated before any of their combinations? Ideally all in a single macro-cycle so the UI doesn't update with partial results.

I tried adding asapScheduler as the last parameter on combineLatest, but it doesn't seem to work, with some inputs updating before combineLatest is called and some after triggering more calls.

I'd also like to be able to add another level of combinations:

EntityStore.selectAll()
  -> pluck A  \     /  combineLatest(A, B) -> map Q   \     / combineLatest(Q, R) -> map W
  -> pluck B  |    |   combineLatest(A, C) -> map R   |    |  combineLatest(Q, S) -> map X
  -> pluck C  |-> -|   combineLatest(B, E) -> map S   |-> -|  combineLatest(S, T) -> map Y
     ...      |    |   ...                            |    |  ...                         
  -> pluck N  /     \  combineLatest(C, D) -> map U   /     \ combineLatest(R, U) -> map Z

How do I ensure that A..N are all calculated before Q..U and similarly, Q..U before W..Z?

Brian
  • 563
  • 1
  • 5
  • 15
  • TBH your illustration is misleading to me. It appears as if each `pluck` should be followed by a corresponding `combineLatest`. But if I understand correctly, all `pluck`s should be complete before triggering the `combineLatest`s. Could you please show a minimal reproduction of your implementation instead? – ruth Aug 05 '20 at 18:43
  • Yes, you understood correctly. All the plucks should complete before any of the combineLatest's – Brian Aug 05 '20 at 18:45
  • And should the `combineLatest`s be sequential or is it ok for them to be parallel? – ruth Aug 05 '20 at 18:47
  • They can be parallel. The idea is that all vertical stacks between the group transitions marked `} -> {` can be parallel, and each group transition must be sequential. So plucks A..N can be parallel, but must complete before the first group of combineLatest operators which themselves can run in parallel, before the next group. Hope this clears things up – Brian Aug 05 '20 at 18:50

0 Answers0