I have two behaviorSubjects
offset = new behaviorSubject<sring>(null)
filter = new behaviorSubject<string>(null)
I do the following..
combineLatest(
this.offset, // last item in the list, ID for example
this.filter // can be any string
).pipe(
mergeMap(([offset, filter]) => this.getChunkOfTen(offset, filter)),
scan((acc, chunkOfTen) => {
return { ...acc, ...chunkOfTen }
}, {}),
map(results => Object.values(results)) // to be able to loop on the frontend
)
When the page loads I get 10 records from DB, onScroll I get 10 more and 10 more.. that's what mergeMap and scan are in charge of (as expected).
onFilter all the existing records are gone (as expected) and I get NEW 10 filtered records from DB, NOW when I scroll I DO NOT get more records and I have them in DB.
as far as I know the problem lays.. in scan operator
is there an if else operator? or some other operators I can use before scan?