loading
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// https://stackoverflow.com/a/51751657/4035
const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;

const { of, from } = require("rxjs");
const { tap, map, catchError } = require("rxjs/operators");
const { ajax } = require("rxjs/ajax");

const { log, info, error, warn } = console;
// of(1, 2, 3).subscribe(log);

function createXHR() {
  return new XMLHttpRequest();
}

ajax({ createXHR, url: `https://api.github.com/users?per_page=5` })
  // .getJSON(`https://api.github.com/users?per_page=5`)
  .pipe(
    map(userResponse => console.log("users: ", userResponse)),
    catchError(error => {
      console.log("error: ", error);
      return of(error);
    })
  )
  .subscribe(log);

// const packageName = "react";
// ajax
//   .getJSON(`https://api.npms.io/v2/search/suggestions?q=${packageName}`)
//   .pipe(
//     // map(userResponse => console.log("users: ", userResponse)),
//     tap(e => info(`e`, e))
//   )
//   .subscribe(log);