Skip to content

Instantly share code, notes, and snippets.

@MoLow
Last active May 19, 2021 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MoLow/ffe4442027965037c76a0cefa8ac2adf to your computer and use it in GitHub Desktop.
Save MoLow/ffe4442027965037c76a0cefa8ac2adf to your computer and use it in GitHub Desktop.
infinite scroll
Observable.fromEvent(this.scrollElement.nativeElement, 'scroll')
.map((e: MouseEvent) => (e.target as HTMLElement).scrollTop * 100 / ((e.target as HTMLElement).scrollHeight - (e.target as HTMLElement).clientHeight))
.pairwise()
.filter(([h1, h2]) => h1 < h2 && h1 > 80)
.startWith([0, 0])
.exhaustMap((x, i) => this.notificationService.getNotifications(i).delay(1000))
.takeWhile(notifs => notifs && notifs.list && notifs.list.length)
.scan((acc, val) => ({ count: val.count, list: [...acc.list, ...val.list || []] }), { list: [], count: 0 });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment