Higher-order Observables in RxJS 5 and RxPHP
When developing browser applications, we very often need to make AJAX calls to fetch data asynchronously. For example, in Angular2, this is very common, and in fact, any AJAX request made using Angular2's HTTP service returns an Observable where we typically chain the map()
operator to decode JSON and then use subscribe()
to be notified when the response is ready.
We can simulate such a situation with the following code:
// http_mock_01.js const Rx = require('rxjs/Rx'); let data = '[{"name": "John"},{"name": "Bob"},{"name": "Dan"}]'; Rx.Observable.of(data) .map(response => JSON.parse(response)) .subscribe(value => console.log('Next:', value));
Variable data contains a JSON-serialized array of objects that we decode and pass to the observer. The output looks like the following:
$ node http_mock_01.js Next: [ { name: 'John&apos...