Skip to content

Commit

Permalink
adding typeaheads to prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
rmccar committed Mar 16, 2020
1 parent 72b8e80 commit 7aa4739
Show file tree
Hide file tree
Showing 37 changed files with 1,248 additions and 1,140 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"presets": ["stage-2", "babel-preset-react", "babel-preset-es2015"],
"plugins": ["transform-class-properties"]
"plugins": ["transform-class-properties", "plugin-transform-runtime"]
}
Original file line number Diff line number Diff line change
@@ -1,49 +1,31 @@
export default class AbortableFetch {
class AboratableFetch {
constructor(url, options) {
this.url = url;
this.options = options;
this.controller = new window.AbortController();
this.status = 'UNSENT';
this.options = { ...options, signal: this.controller.signal };

fetch(url, options).then(response => {
if (response.ok) {
this.thenCallback(response);
} else {
this.catchCallback(response);
}
});
}

send() {
this.status = 'LOADING';
then(callback) {
this.thenCallback = callback;
return this;
}

return new Promise((resolve, reject) => {
abortableFetch(this.url, { signal: this.controller.signal, ...this.options })
.then(response => {
if (response.status >= 200 && response.status < 300) {
this.status = 'DONE';
resolve(response);
} else {
this.status = 'DONE';
reject(response);
}
})
.catch(error => {
this.status = 'DONE';
reject(error);
});
});
catch(callback) {
this.catchCallback = callback;
return this;
}

abort() {
this.controller.abort();
}
}

function abortableFetch(url, options) {
return window.fetch(url, options)
.then(response => {
if (response.ok) {
return response;
} else {
const error = new Error(response.statusText);
error.response = response;
throw error;
}
})
.catch(error => {
throw error;
});
}
export default (url, options) => new AboratableFetch(url, options);

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 7aa4739

Please sign in to comment.