-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathcustom-http-client.mjs
46 lines (44 loc) · 1.37 KB
/
custom-http-client.mjs
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
35
36
37
38
39
40
41
42
43
44
45
46
import { Grid } from '../../dist/main.esm.js'
export default {
name: 'CustomHttpClient',
components: {
Grid
},
data() {
return {
columns: ['Name', 'Language', 'Released At', 'Artist'],
server: {
url: 'https://api.scryfall.com/cards/search?q=Inspiring',
data: opts => {
return new Promise((resolve, reject) => {
// let's implement our own HTTP client
const xhttp = new XMLHttpRequest()
xhttp.onreadystatechange = function () {
if (this.readyState === 4) {
if (this.status === 200) {
const resp = JSON.parse(this.response)
// make sure the output conforms to StorageResponse format:
// https://github.com/grid-js/gridjs/blob/master/src/storage/storage.ts#L21-L24
resolve({
data: resp.data.map(card => [card.name, card.lang, card.released_at, card.artist]),
total: resp.total_cards
})
} else {
reject()
}
}
}
xhttp.open('GET', opts.url, true)
xhttp.send()
})
}
},
pagination: {
limit: 5
}
}
},
template: `
<div><grid :columns="columns" :server="server" :pagination="pagination"></grid></div>
`
}