With RXJS library : I need to store values from the FIRST http request, but keep doing other http request on demand.
I have done this code so far, and that is working. But I think there is a more elegant way.
const Rx = require("rxjs");
let numHttp = 0;
const httpRequest = () => {
let a = [];
numHttp = numHttp + 1;
for (let i = 0; i < 10; ++i) {
a.push({ num: i, http: numHttp });
};
return new Rx.BehaviorSubject(a)
.do(a => {
console.log("antoher http request");
if (getC.getValue() === undefined) {
getC.next(a)
}
})
// .do(n => { if (getB.) getB.next(n) })
}
const getB = () => {
const a = new Rx.BehaviorSubject();
return a
};
getC = getB();
httpRequest().subscribe(d => d);
httpRequest().subscribe(d => d);
getC.subscribe(data => console.log('cache', data))
httpRequest().subscribe(d => d);
httpRequest().subscribe(d => d);