What is the difference between Observables and common Javascript events?

Asked

Viewed 95 times

3

I have seen a lot of people talking about Observables and about Pattern Observer in general, mainly from the Rx JS 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 "articipial" observers? The function of the two would not be the same?

1 answer

1

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

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

The function that is paired with the "add to list" function sends an event saying "add X to the list"; something receives that event and adds X to the list; when that list changes, it triggers a Subscriber for all the observers with the necessary information (normally the new date).

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.