Don't use a util function for a thing that exists 1x in the code

This commit is contained in:
Bryan Housel
2021-08-16 14:23:24 -04:00
parent 746417e1f4
commit 1282d3b059
3 changed files with 9 additions and 14 deletions
+9 -2
View File
@@ -1,4 +1,3 @@
import { utilFetchJson } from '../util/util';
import parseVersion from 'vparse';
// Double check this resolves to iD's `package.json`
import packageJSON from '../../package.json';
@@ -60,7 +59,15 @@ export function coreFileFetcher() {
let prom = _inflight[url];
if (!prom) {
_inflight[url] = prom = utilFetchJson(url)
_inflight[url] = prom = fetch(url)
.then(response => {
// fetch in PhantomJS tests may return ok=false and status=0 even if it's okay
if ((!response.ok && response.status !== 0) || !response.json) {
throw new Error(response.status + ' ' + response.statusText);
}
if (response.status === 204 || response.status === 205) return; // No Content, Reset Content
return response.json();
})
.then(result => {
delete _inflight[url];
if (!result) {
-1
View File
@@ -27,7 +27,6 @@ export { utilEntityOrMemberSelector } from './util';
export { utilEntityOrDeepMemberSelector } from './util';
export { utilEntitySelector } from './util';
export { utilFastMouse } from './util';
export { utilFetchJson } from './util';
export { utilFunctor } from './util';
export { utilGetAllNodes } from './util';
export { utilGetSetValue } from './get_set_value';
-11
View File
@@ -580,14 +580,3 @@ export function utilUnicodeCharsCount(str) {
export function utilUnicodeCharsTruncated(str, limit) {
return Array.from(str).slice(0, limit).join('');
}
// Variation of d3.json (https://github.com/d3/d3-fetch/blob/master/src/json.js)
export function utilFetchJson(resourse, init) {
return fetch(resourse, init)
.then((response) => {
// fetch in PhantomJS tests may return ok=false and status=0 even if it's okay
if ((!response.ok && response.status !== 0) || !response.json) throw new Error(response.status + ' ' + response.statusText);
if (response.status === 204 || response.status === 205) return;
return response.json();
});
}