Search code examples
javascriptrxjsfrp

Why does a sequence get called multiple times when there are only one subscriber?


I have an example here. There is only one subscriber, but why does a sequence get called 3 times (3 'call' messages)? Imagine that we have API call and...it's a problem. How to fix it?


Solution

  • Because it is not shared and each subscriber triggers the entire chain of transformations. To fix that, call the share operator:

              .map(micr => micr.toUpperCase()).share();