There are hot, cold, and warm Observables. What do we actually mean by that? For starters, let's say that most things you will deal with are cold Observables. Not helping? If we say that cold Observables are lazy, does that help? No? OK, let's talk about Promises for a second. Promises are hot. They are hot because when we execute their code, it happens straight away. Let's see an example of that:
// hot-cold-warm/promise.js function getData() { return new Promise(resolve => { console.log("this will be printed straight away"); setTimeout(() => resolve("some data"), 3000); }); } // emits 'some data' after 3 seconds getData().then(data => console.log("3 seconds later", data));
If you come from a non-RxJS background, you will most likely, at this point, think: OK, yes, that's what I expected. This is the point we are trying to make, though: Calling getData()
makes your code run straight away. This differs from RxJS in the sense that similar...