-1

What is the difference between rxjs/Observables and JQuery, when I use $.get() or any other async function?

Both are asynchronous and reactive?

Yevhen Horbunkov
  • 14,965
  • 3
  • 20
  • 42
Nataly
  • 17
  • 3
  • See this question: ["What is the difference between Promises and Observables?"](https://stackoverflow.com/questions/37364973/what-is-the-difference-between-promises-and-observables?rq=1) – kos Apr 23 '19 at 08:26

1 Answers1

1

$.get() is not Reactive in the sense that is meant with RxJS or Observables in general.

The idea is that with Observables you can define a stream of data, how it flows through a pipeline of transformations and other operators. This way you can reason about your logic more easily, and transform a single source to multiple use cases.

With $.get() or fetch() (ES6+) for that matter, you are not defining a pipeline, but you are retrieving directly at this point.

An Observable will be defined, but remain "paused" until someone actively starts listening to it.

This behavior however is not the main difference, there's a pattern called the Observable pattern that might give you a closer idea of what working "Reactive" exactly means, and how it differs from the imperative way of using JQuery's $.get() or ES6's fetch()

Bjorn 'Bjeaurn' S
  • 3,861
  • 2
  • 18
  • 29