mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 02:44:02 +00:00
refactor: separate transit sources and request service
This commit is contained in:
1 parent
e284a9cd34
commit
3155e4e0bf
26 files changed
+1444
-1157
No files matched your search
@@ -0,0 +1,22 @@
|
||||
import { fetchTransitHistory } from '../../sources/transitHistory.js';
|
||||
|
||||
/** Request transit snapshots through caller-owned transport. */
|
||||
export function createTransitSource({
|
||||
fetchImpl = (...args) => fetch(...args),
|
||||
} = {}) {
|
||||
return {
|
||||
getHistory(feedId, vehicleId, { signal } = {}) {
|
||||
signal?.throwIfAborted();
|
||||
return fetchTransitHistory(feedId, vehicleId, signal, fetchImpl);
|
||||
},
|
||||
requestSnapshot(feedId, { signal } = {}) {
|
||||
signal?.throwIfAborted();
|
||||
if (typeof feedId !== 'string' || !feedId || feedId.length > 160)
|
||||
throw new TypeError('A transit feed identifier is required');
|
||||
return fetchImpl(`/api/transit/vehicles/${encodeURIComponent(feedId)}`, {
|
||||
signal,
|
||||
headers: { Accept: 'application/json' },
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user