Im pretty new to RxJs and I would like to understand how best to work with Rx in conjunction with Promises.
What I want to create is a service in Angular that acts as an event dispatcher template and fires an event after the promise is completed. I also demand that if there are no subscribers (events), the observable will never be called. The last thing I want to say is that any subsequent subscribers to the observable will get the same result without starting another request to the server. I managed to implement my own solution here:
Now at any time when I sign up, a new βlistenerβ to subject to the observed will be pulled. Any new subscribers will receive a cache value without touching the server again.
So, inside my "consumer" (Angular directive), I would like to do something like this:
Any future COUNTRIES_LOADED observer subscribers MUST NOT trigger a $ http request. Similarly, if the directive is never included on the page, $ http will never be called.
The solution above works, however, I do not know about the potential flaws and memory problems of this approach. Is this a valid solution? Is there a better / more suitable way to achieve this with RxJs?
Many thanks!
source share