-
-
Save thedamon/86601ba009bfd05cb791 to your computer and use it in GitHub Desktop.
Trying to string together fetching promises
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {fetchHistoryData} from '/service' | |
function initChart(config = this.defaultConfig){ | |
fetchHistoryData() | |
.then((response)=> { | |
buildChart(); | |
}).catch(()=>{ | |
console.error('Could not get chart data.'); | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fetchData(url, options = {mode: 'cors'}, formatter = ((data)=>data)){ | |
console.log(url); | |
return window.fetch(url, options) | |
.then(status) | |
.then(formatter) | |
.then(function(data){ | |
return data; | |
}) | |
.catch(throwError); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {fetchData} from './fetchUtils' | |
export function fetchHistoryData(){ | |
return Promise.all([fetchHistory('set1'), fetchHistory('set2')]); | |
//.then((result)=>result); ?? | |
} | |
function fetchHistory(name){ | |
return new Promise((resolve)=>{ | |
const url = createHistoryUrl(name); | |
resolve (fetchData(url, {mode:'no-cors'}, historyFormatter)); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment