<!DOCTYPE html>
<html>
<head>
<script src="https://npmcdn.com/@reactivex/rxjs@5.0.0-beta.6/dist/global/Rx.umd.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="script.js"></script>
</head>
<body>
</body>
</html>
let subject = new Rx.ReplaySubject();
let array = ['5', 'd', '5', '9', '3', '2', 'x', '4', '8'];
let requestStream = Rx.Observable.interval(400).take(array.length).map(i => array[i])
.map(x => parseInt(x))
.filter(x => {
return !isNaN(x)
})
.map(x => `/api/myurl/${x}`);
setTimeout(function() {
subject.subscribe(function(val) {
$('body').append('<div>' + val + '</div>');
});
subject.next('hi there');
}, 2000);
requestStream.subscribe(function(val) {
subject.next(val);
});
Rx.ReplaySubject() demo
With ReplaySubject we receive items that were emitted before we subscribed.