When I googled for it, I was taken to pages like CycleJS, RxJS etc. It's still unclear to me what Observables are, how they can be used in JavaScript and what's the benefits etc. Could someone please be generous enough to give me an overview here?
I use observables with knockout.js.
An observable is an object, array or property that triggers a change event.
You can subscribe to this event and do what ever you want to do with that information (for example: validate values, update the DOM, trigger an API-request, ...).
Sai Kishore Komanduri
Engineering an eGovernance Product | Hashnode Alumnus | I love pixel art
Observables are simply the objects in an observer pattern. Wikipedia defines it succinctly.
The simplest analogy of an observer pattern can be given using a DOM event. Let's say you have a DOM element
<button>with"button"as itsidattribute; and consider the following code:var button = document.findElementById("button"); button.addEventListener("click", myAwesomeClickHandlerFunction);If you call the
<button>node, a subject (or an observable); the event listener "click" on the<button>node is analogous to an observer; andmyAwesomeClickHandlerFunction, its method.You can read this article and study the (JS) code within, for a yet better, and deeper understanding of the observer pattern. The CycleJS, RxJS pages that you have come across are, I believe, documentation for the RxJS implementation of observables / observer pattern (apparently there's RxJS underneath Cycle.js).