Whatâs Reactive?
Letâs start by looking at a little program. This program retrieves data from different sources with the click of a button. It has the following requirements:
-
It must unify data from two different locations that use different JSON structures.
-
The final result should not contain any duplicates.
-
The user should not be able to click the button more than once every second, to avoid requesting data too many times.
Using RxJS, we would write something like this:
â | âimportâ { Observable } âfromâ â"rxjs"â; |
â | |
â | âconstâ button = document.getElementById(â"retrieveDataBtn"â); |
â | âconstâ source1 = Observable.ajax.getJSON(â"/resource1"â).pluck(â"name"â); |
â | âconstâ source2 = Observable.ajax.getJSON(â ... |
Get Reactive Programming with RxJS 5 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.