I have a component which triggers an onScrollEnd
event when the last item in a virtual list is rendered. This event will do a new API request to fetch the next
I think you could achieve what you want just by restructuring your chain (I'm omitting tap
calls that trigger loading for simplicity):
search$.pipe(
switchMap(searchterm =>
concat(
userService.getUsers(0, searchterm),
offset$.pipe(concatMap(offset => userService.getUsers(offset, searchterm)))),
).pipe(
map(({ data }) => data.map((user) => ({
label: user.name,
value: user.id
}))),
scan((acc, curr) => [...acc, ...curr], []),
),
),
);
Every emission from search$
will create a new inner Observable with its own scan
that will start with an empty accumulator.