Skip to content

Commit

Permalink
Switch from XHR to fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrk24 committed Mar 29, 2024
1 parent f2cb27b commit b8f42ef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
18 changes: 5 additions & 13 deletions src/data.civet
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
type { YamlData } from ./yamlTypes.civet
XHRError from ./xhrError.civet

req := new XMLHttpRequest
responsePromise := new Promise<string> (resolve, reject) =>
req.addEventListener 'progress', console.info
req.addEventListener 'load', -> resolve @responseText
req.addEventListener 'error', (e) -> reject new XHRError 'Failed to fetch data', @, e
req.open 'GET', './data.json'
req.setRequestHeader 'Accept', 'application/json, application/*;q=0.9, */*;q=0.8'
req.send()
responseText := await responsePromise
// using JSON.parse instead of setting responseType to get a thrown Error instead of null
response: YamlData := JSON.parse responseText
response := await fetch './data.json',
headers: Accept: 'application/json, application/*;q=0.9, */*;q=0.8'

export default response
data: YamlData := await response.json()

export default data
15 changes: 0 additions & 15 deletions src/xhrError.civet

This file was deleted.

0 comments on commit b8f42ef

Please sign in to comment.