RxJS Playground

A blank canvas to play / experiment with RxJS: https://github.com/Reactive-Extensions/RxJS

by amindunited

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/4.0.7/rx.all.js"></script>

JavaScript

console.clear();

var array = ["a", "d", "c"];

var o1 = Rx.Observable.from(array); // 'a, d, c
o1.subscribe(x => console.log('fromarray:', x));

console.log('o1', o1);

setTimeout(() => {

}, 2000);


function fakeApiCall(value) {
  var lookupValues = { "a": 123, "b": 234, "c": 345, "d": 456 };
	return Rx.Observable.just({ id: value, lookup: lookupValues[value] });
}

var o2 = o1.flatMap(x => {
	// here we return an observable using the values in o1
  // which could be an api call returning a value
  return fakeApiCall(x);
});

o2.subscribe(x => console.log('flatmap result:', x));