What is the difference between Observables and common JavaScript events?

3

I've seen a lot of people talking about Observables and about the Observer pattern in general, mostly from the JS Rx library. What is the difference between observers and the events we usually treat, such as onclick , onkeypress , onkeydown , etc? If we already have the possibility to create and respond to events, why do we need "artificial" Observers? Would not the two be the same?

    
asked by anonymous 28.01.2017 / 15:39

1 answer

1

The main difference between the two is that a Observer is for when something changes , whereas a Event occurs when something happens .

The practical example of this would be, in a whole list:

The function that is associated with the "add to list" button sends an event saying "add X to list"; something receives this event and adds X to the list; When this list changes, it fires a Subscriber for all observers with the required information (usually the new date).

That is: One does not replace the other and can be used side by side.

    
29.01.2017 / 18:49