mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
refactor(fires): separate source, rendering and interaction components
This commit is contained in:
1 parent
e99cc8cf68
commit
6a9f13eab8
28 files changed
+2540
-1731
No files matched your search
@@ -0,0 +1,29 @@
|
||||
/** Construct the existing live-fire endpoint without making a request. */
|
||||
export function createFirmsSource({
|
||||
fetchImpl = (...args) => globalThis.fetch(...args),
|
||||
} = {}) {
|
||||
return {
|
||||
async getSnapshot({ signal } = {}) {
|
||||
signal?.throwIfAborted();
|
||||
const response = await fetchImpl('/api/firms', {
|
||||
signal,
|
||||
cache: 'no-store',
|
||||
});
|
||||
let payload;
|
||||
try {
|
||||
payload = await response.json();
|
||||
} catch {
|
||||
/* status below remains authoritative */
|
||||
}
|
||||
signal?.throwIfAborted();
|
||||
if (!response.ok) {
|
||||
if (response.status === 503 && payload?.error === 'no_key')
|
||||
return { keyRequired: true };
|
||||
throw new Error(`FIRMS HTTP ${response.status}`);
|
||||
}
|
||||
if (!Array.isArray(payload?.fires))
|
||||
throw new Error('Malformed fire snapshot');
|
||||
return payload;
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user