mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 02:44:02 +00:00
refactor(app): share application components and request services
This commit is contained in:
1 parent
a0a0128a59
commit
a67bc60a29
84 files changed
+2798
-1731
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import { createSourceSlot } from '../app/sourceSlot.js';
|
||||
import { createApplicationRequestServices } from './requests.js';
|
||||
|
||||
// Compatibility owners are page-scoped, like the viewer and its layer registry.
|
||||
const defaults = createApplicationRequestServices();
|
||||
const slots = Object.fromEntries(
|
||||
Object.entries({
|
||||
boundaries: ['query'],
|
||||
terrain: ['getHeights'],
|
||||
regional: ['getBrief'],
|
||||
weather: ['getConditions'],
|
||||
summary: ['summarize'],
|
||||
}).map(([name, methods]) => [
|
||||
name,
|
||||
createSourceSlot(defaults[name], methods, `${name} service`),
|
||||
]),
|
||||
);
|
||||
export const applicationServices = Object.freeze(
|
||||
Object.fromEntries(
|
||||
Object.entries(slots).map(([name, slot]) => [name, slot.source]),
|
||||
),
|
||||
);
|
||||
|
||||
/** Supply selected services before constructing the application; release after its consumers. */
|
||||
export function configureApplicationServices(services) {
|
||||
const releases = [];
|
||||
try {
|
||||
for (const [name, service] of Object.entries(services)) {
|
||||
if (!slots[name])
|
||||
throw new TypeError(`Unknown application service: ${name}`);
|
||||
releases.push(slots[name].configure(service));
|
||||
}
|
||||
} catch (error) {
|
||||
for (const release of releases.reverse()) release();
|
||||
throw error;
|
||||
}
|
||||
return () => {
|
||||
for (const release of releases.reverse()) release();
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user