How to tell whether an Observable is "awaiting" another with RxJS (for Ajax request indicator, for example)

StackOverflow https://stackoverflow.com/questions/16153511

سؤال

While learning RxJS, I'm wondering:

How to create an Observable that tells whether Observable X has had value after Observable Y?

Example need would be to tell whether there is an Ajax request pending response? Like awaiting with Bacon.js.

هل كانت مفيدة؟

المحلول

While formulating the question, I found one answer:

  • map (select within RxJS) another Observable (the one triggering the request) to true
  • map another Observable (response one) to false
  • merge

i.e.

var availabilityPending = usernameToValidate.select(function() {return true;})
         .merge(usernameAvailable.select(function() {return false;}));

Don't know if there's already a helper for this kind of behaviour?

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top