Skip to content

Instantly share code, notes, and snippets.

@thedamon
Last active March 28, 2016 00:47
Show Gist options
  • Save thedamon/86601ba009bfd05cb791 to your computer and use it in GitHub Desktop.
Save thedamon/86601ba009bfd05cb791 to your computer and use it in GitHub Desktop.
Trying to string together fetching promises
import {fetchHistoryData} from '/service'
function initChart(config = this.defaultConfig){
fetchHistoryData()
.then((response)=> {
buildChart();
}).catch(()=>{
console.error('Could not get chart data.');
});
}
}
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);
}
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