rxjs

Imperative programming is a most common programming paradigm, which involves executing statements that change a programs state, like calling a function that change the values of variables.

like a add function that takes 2 parameters and returns the sum value ....

But With reactive programming we stop thinking about variables, instead we think in terms of streams and how those streams are connected together.

**so the idea is we can define an application as a series of different streams with operations that connect the different streams together and which are automatically called when new values are pushed onto those streams.

#observable basically can be thought of as a data source.
in Angular observables basically just is an object we import from a third party package called RxJS,

the observable here is implemented in a way that it follows the observable pattern.

Something like we have an observable and the other end we have an observer in between we have a stream or a timeline.

And on this timeline we can have multiple events emitted by the observable.
(You could say emitted by that observable depending on the data source of that observable of course.)

We can program the observable to emit data on certain events.

For example Observables could be connected to a button and therefore when ever a user clicks on it an event is emitted automatically.

And there are three ways of handling data packages.
You can get to handle the normal data, you can handle errors, finally you can handle the completion of the observable.
because these are the three types of data packages you can receive and these hooks will execute our code.

So you can write business logic on what should happen if I receive a new data package, what should happen if I receive
an error. What should happen when the observable eventually completes. all though all the observables doesn't have to complete.

[And historically we might have used callbacks or promises.
And it's not necessarily bad to use them, observables is just a different approach of handling asynchronose data, that a
different alternative.]

By default observables are cold and only become hot when they get their first subscriber.
If we want to stop listening to changes, we can unsubscribe by getting a reference and clean up.

----

The Rx team use something called a marble diagram to visually describe an operators function.
                                   --------------

Observables acts as a blueprint for how we want to create streams, subscribe to them, react to new values, and combine streams together to build new ones.
RxJS (*R*eactive E*x*tensions for *J*ava*S*cript) is a library that gives us an implementation of Observables for JavaScript.

Observer : receives notifications from Observable.

By default observables are cold and only become hot when they get their first subscriber.

We can pass in our observer when calling subscribe or by passing onNext, onError and onCompleted callbacks.

Observable/Observer behaviours:
onNext, called for each element in the observable sequence.
onError, called only once in case of an error.
onCompleted, called only once when the stream finishes.

If we want to stop listening to changes, we can unsubscribe by getting a reference and clean up.