Posts

Showing posts with the label RxJS

The auditMap operator for RxJS

Image
RxJs has lots of custom operators but there was recently a problem I could not solve with them. The Problem I have a page with a back button. Within the page you can change settings, which e.g. updates something in a database using a REST API. The page has no save button, so every change is saved instantly. The problem is now that I have to ensure that the API calls are finished before I route to another page. So when the user changes a setting and clicks the back button, I have to block the routing until the api calls returned successfully. So imagine the user is changing multiple settings very quickly and the API call is slow: He ticks a checkbox => Call the API He changes an address => Call the API He unticks again => Call the API He clicks on the back button Wait until the settings are saved Route to the back page So I need an operator which does not emit when there are "next" operations in the queue. I don't need all operations to be executed as each operati...

What is the difference between Cold and Hot Observables

🔥vs🥶 🔥 Allegory HOT Image you are watching the news on TV but you've started watching in the middle of the show. You don't know what was reported before and you will not know what happened if you do not watch the show from the beginning. If someone else has started watching the news after you, he will not have all the information you have, only from the point onwards where he started watching. The news broadcast on TV is HOT 🔥.  This means there is one source which emits information and you can subscribe to it. But you will only get the information from the time you've subscribed. 🥶 Allegory COLD Imagine you want to create a bank account. You go to the bank and they will tell you: Bring your ID Fill in the form Sign it Login to you mobile app etc. The next person who wants to create an account will get probably the same information in the same order. Creating a bank account is COLD 🥶 This means that each time you want to get the information from the source, the source...