mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 10:53:59 +00:00
refactor: separate earthquake source and display ownership
This commit is contained in:
1 parent
965a44860f
commit
d1d938babe
11 files changed
+540
-339
No files matched your search
@@ -0,0 +1,20 @@
|
||||
import { normalizeEarthquakeSnapshot } from './model.js';
|
||||
const API_URL =
|
||||
'https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson';
|
||||
/** Request and validate a complete USGS snapshot before it can replace displayed events. */
|
||||
export function createUsgsEarthquakeSource({
|
||||
fetchImpl = (...args) => globalThis.fetch(...args),
|
||||
} = {}) {
|
||||
return {
|
||||
async getSnapshot({ signal } = {}) {
|
||||
signal?.throwIfAborted();
|
||||
const response = await fetchImpl(API_URL, { signal });
|
||||
if (!response.ok) throw new Error(`USGS HTTP ${response.status}`);
|
||||
const payload = await response.json();
|
||||
signal?.throwIfAborted();
|
||||
const rows = normalizeEarthquakeSnapshot(payload);
|
||||
if (!rows) throw new Error('Malformed USGS response');
|
||||
return rows;
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user