Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. import Pagination from "@77io/pagination";
  2. import { last, reduce } from "rxjs/operators";
  3.  
  4. // Setup the basic options
  5. const baseUrl = wordpressRoot + "/wp-json/wp/v2/posts";
  6. const headers = {
  7. accept: "application/json"
  8. };
  9.  
  10. const sub = Pagination(baseUrl, headers)
  11. .pipe(
  12. reduce((arr: any[], page: any[]) => {
  13. return arr.concat(page);
  14. }, []),
  15. last()
  16. )
  17. .subscribe((allPosts: any[]) => {
  18. console.log("I got all posts!");
  19. sub.unsubscribe();
  20. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement