mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-08 04:14:02 +00:00
refactor(cyclones): drop defensive shared-context state and checks
This commit is contained in:
1 parent
5e64e599e1
commit
5bab5ec26d
3 files changed
+10
-32
No files matched your search
@@ -3,9 +3,8 @@ import * as context from '../../data/contextStore.js';
|
||||
|
||||
/** Wire cyclone selection to the application shared context. */
|
||||
export function createApplicationCyclones(options) {
|
||||
const browserContext = typeof window !== 'undefined' ? { context } : {};
|
||||
return createCyclonesLayer({
|
||||
...browserContext,
|
||||
context: typeof window !== 'undefined' ? context : null,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -84,7 +84,6 @@ export function createCyclonesLayer({
|
||||
selectionIntent = 'auto',
|
||||
navigationGeneration = 0,
|
||||
selectedContextStormId = null,
|
||||
selectedContextEntity = null,
|
||||
clickHandler = null,
|
||||
removeClickCapture = null;
|
||||
let enabled = false,
|
||||
@@ -98,20 +97,19 @@ export function createCyclonesLayer({
|
||||
function clearSelectedContext({ evicted = false } = {}) {
|
||||
if (selectedContextStormId) {
|
||||
if (!evicted)
|
||||
context?.clearSelectedEntityContextForLayer?.('weather-cyclones');
|
||||
context?.removeEntityContextsForLayer?.('weather-cyclones');
|
||||
context.clearSelectedEntityContextForLayer('weather-cyclones');
|
||||
context.removeEntityContextsForLayer('weather-cyclones');
|
||||
}
|
||||
selectedContextStormId = null;
|
||||
selectedContextEntity = null;
|
||||
}
|
||||
|
||||
// Callers publish only while selectedId names a storm in the snapshot.
|
||||
function publishSelectedContext({ announce = false } = {}) {
|
||||
const storm = selected();
|
||||
if (!context) return;
|
||||
selectedContextEntity ||= { show: true };
|
||||
const entity = {};
|
||||
const contextId = `cyclone:${storm.id}`;
|
||||
const record = context.registerEntityContext?.(selectedContextEntity, {
|
||||
context.registerEntityContext(entity, {
|
||||
id: contextId,
|
||||
layerId: 'weather-cyclones',
|
||||
layerName: 'Cyclone advisories',
|
||||
@@ -145,10 +143,9 @@ export function createCyclonesLayer({
|
||||
: undefined,
|
||||
},
|
||||
});
|
||||
if (!record) return;
|
||||
selectedContextStormId = storm.id;
|
||||
if (announce) context.selectEntityContext?.(selectedContextEntity);
|
||||
context.removeEntityContextsForLayer?.('weather-cyclones', {
|
||||
if (announce) context.selectEntityContext(entity);
|
||||
context.removeEntityContextsForLayer('weather-cyclones', {
|
||||
retainIds: new Set([contextId]),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -488,12 +488,7 @@ test('shared cyclone context distinguishes switches, deliberate clears and feed
|
||||
assert.equal(store.entities.size, 0);
|
||||
|
||||
h.layer.setParams({ stormId: 'ep152026' });
|
||||
const record = store.entities.get('cyclone:ep152026');
|
||||
assert.equal(record.layerId, 'weather-cyclones');
|
||||
assert.equal(record.source, 'NOAA NHC / CPHC');
|
||||
assert.equal(record.label, 'Fifteen-E');
|
||||
assert.equal(record.latitude, 15.5);
|
||||
assert.equal(record.longitude, -125.8);
|
||||
assert.equal(store.entities.get('cyclone:ep152026').label, 'Fifteen-E');
|
||||
let properties = await selectedProperties();
|
||||
assert.equal(properties.classification, 'PTC');
|
||||
assert.equal(properties.classificationName, 'Post-tropical cyclone');
|
||||
@@ -652,24 +647,11 @@ test('cyclone clears leave another layer selection and its records alone', async
|
||||
'no clear is reported for a foreign selection',
|
||||
);
|
||||
|
||||
// A cyclone clear does not report a dangling foreign selection as evicted.
|
||||
store.entities.delete('flight:abc123');
|
||||
h.layer.disable();
|
||||
assert.equal(store.selectedEntityId, 'flight:abc123');
|
||||
assert.equal(events.length, before);
|
||||
|
||||
// A cyclone feed failure does not evict a dangling foreign selection.
|
||||
store.entities.delete('flight:abc123');
|
||||
let fail = false;
|
||||
const other = open({
|
||||
getSnapshot: async () => {
|
||||
if (fail) throw new Error('Network unavailable');
|
||||
return snapshot();
|
||||
},
|
||||
});
|
||||
other.layer.enable();
|
||||
await other.layer.update();
|
||||
fail = true;
|
||||
await other.layer.update();
|
||||
assert.equal(events.length, before);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user