Skip to content

Commit

Permalink
use XMLHttpRequest instead of fetch fix (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
vanwagonet committed Dec 22, 2016
1 parent 9993b31 commit e3221e3
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/repl/utils/gist.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ export function getComponentFromGist ( id ) {
let cancelled = false;

if ( !cache[ id ] ) {
cache[ id ] = fetch( `https://api.github.com/gists/${id}`, { mode: 'cors' })
.then( r => r.json() )
cache[ id ] = new Promise( ( resolve, reject ) => {
const request = new XMLHttpRequest();
request.open( 'GET', `https://api.github.com/gists/${id}` );
request.onload = () => resolve( request );
request.onerror = () => reject( new TypeError('Network request failed') );
request.send();
} )
.then( r => JSON.parse(r.responseText) )
.then( gist => {
const sourceFile = gist.files[ 'component.html' ];
const source = sourceFile && sourceFile.content;
Expand Down Expand Up @@ -51,7 +57,14 @@ export function saveComponentAsGist ( source, json ) {
}
});

return fetch( `https://api.github.com/gists`, { method: 'POST', body })
.then( r => r.json() )
return new Promise( ( resolve, reject ) => {
const request = new XMLHttpRequest();
request.withCredentials = true;
request.open( 'POST', `https://api.github.com/gists` );
request.onload = () => resolve( request );
request.onerror = () => reject( new TypeError('Network request failed') );
request.send(body);
} )
.then( r => JSON.parse(r.responseText) )
.then( gist => gist.id );
}

0 comments on commit e3221e3

Please sign in to comment.