Wpis z mikrobloga

Staram się zrobić infinite scrolla. Po dojechaniu do dolnej krawędzi ma pobrać nowe itemy listy i zmergować je z obecnym observable, który trzyma dotychczasową listę itemów. Problem w tym, że każdego kolejnego scrolla wykonuje również nadmiarowe requesty po historyczne dane. Wygląda to tak, jakby this.items$ emitowało wszyskie poprzednie stany.
Co robię źlę? Podpowiecie? ;)

items$: Observable;
page = 1;
pageSize = 20;
isLoading = true;

constructor(private itemsService: ItemsService) { }

ngOnInit() {
this.items$ = getItems();
}

onScroll() {
this.page++;
this.items$ = combineLatest([
this.items$,
this.getItems()
])
.pipe(
map(([currentItems, newItems] => [...currentItems, ...newItems ]))
)
}

private getItems() {
return this.itemsService
.getItems({ page: this.page, pageSize: this.pageSize })
.pipe(
map((res) => res.items)
);
}

#angular #angularjs
  • 3