style: format Context component modules

This commit is contained in:
Sameh Khamis committed 2026-09-13 01:41:01 -07:00
1 parent fc369cc65a
commit 3e078ef49d
11 files changed
+1175 -801

No files matched your search

+72 -40
View File
@@ -1,25 +1,38 @@
import { contextLayerEnableBlockReason, isExplicitUserIntentOrigin, runWithContextModeChanging, settleContextModeChange, shouldCaptureContextSession, shouldDeferContextEntryDuringClear } from '../contextModePolicy.js';
import {
contextLayerEnableBlockReason,
isExplicitUserIntentOrigin,
runWithContextModeChanging,
settleContextModeChange,
shouldCaptureContextSession,
shouldDeferContextEntryDuringClear,
} from '../contextModePolicy.js';
export function connectContextManager(manager) {
this.disconnect();
if (this.destroyed) return;
this._dataManager = manager || null;
this._contextManagerUnsubscribe = this._dataManager?.subscribe?.((change) => {
if (String(change?.type || '').startsWith('visibility')) this._handleContextLayerChange(change);
if (String(change?.type || '').startsWith('visibility'))
this._handleContextLayerChange(change);
});
if (typeof this._dataManager?.subscribeVisibilityRequests === 'function') {
this._dataManagerVisibilityRequestUnsubscribe = this._dataManager.subscribeVisibilityRequests((change) => {
if (typeof this._dataManager?.subscribeVisibilityRequests === 'function') {
this._dataManagerVisibilityRequestUnsubscribe =
this._dataManager.subscribeVisibilityRequests((change) => {
if (this.destroyed) return;
if (shouldCaptureContextSession(change)) {
// This event is synchronous with intent publication, before an
// awaited guard or Clear All can alter the rest of the layer set.
// Manager effective visibility already includes both the new entry
// intent and Clear's reserved OFF baseline.
this._captureContextSessionSnapshot({ excludeLayerIds: [change.layerId] });
if (shouldDeferContextEntryDuringClear({
change,
clearInFlight: Boolean(this._clearSelectedLayersPromise),
})) {
this._captureContextSessionSnapshot({
excludeLayerIds: [change.layerId],
});
if (
shouldDeferContextEntryDuringClear({
change,
clearInFlight: Boolean(this._clearSelectedLayersPromise),
})
) {
this._contextModeDeferredEntryIntent = {
layerId: change.layerId,
intentEpoch: change.intentEpoch,
@@ -29,9 +42,9 @@ export function connectContextManager(manager) {
this._syncContextModeButtons();
}
} else if (
change?.layerId === 'rocket-launches'
&& change.enabled === false
&& isExplicitUserIntentOrigin(change.origin, change.layerId)
change?.layerId === 'rocket-launches' &&
change.enabled === false &&
isExplicitUserIntentOrigin(change.origin, change.layerId)
) {
this._contextModeDeferredEntryIntent = null;
if (this._clearSelectedLayersPromise) {
@@ -41,11 +54,14 @@ export function connectContextManager(manager) {
}
}
});
}
if (typeof this._dataManager?.addVisibilityGuard === 'function') {
this._dataManagerVisibilityGuardUnsubscribe = this._dataManager.addVisibilityGuard(async (change) => {
}
if (typeof this._dataManager?.addVisibilityGuard === 'function') {
this._dataManagerVisibilityGuardUnsubscribe =
this._dataManager.addVisibilityGuard(async (change) => {
if (this.destroyed) return null;
const layerName = this._dataManager?.layers?.get(change.layerId)?.module?.name || change.layerId;
const layerName =
this._dataManager?.layers?.get(change.layerId)?.module?.name ||
change.layerId;
const reason = contextLayerEnableBlockReason({
contextMode: this._contextModeEntering || this._contextMode,
change,
@@ -53,23 +69,26 @@ export function connectContextManager(manager) {
});
if (reason) return reason;
if (
change.enabled
&& ['military-awareness', 'rocket-launches'].includes(change.layerId)
&& shouldCaptureContextSession(change)
&& (
!this._contextModeChanging
|| (
change.layerId === 'rocket-launches'
&& this._contextModeDeferredEntryIntent?.intentEpoch === change.intentEpoch
)
)
change.enabled &&
['military-awareness', 'rocket-launches'].includes(change.layerId) &&
shouldCaptureContextSession(change) &&
(!this._contextModeChanging ||
(change.layerId === 'rocket-launches' &&
this._contextModeDeferredEntryIntent?.intentEpoch ===
change.intentEpoch))
) {
const entryMode = change.layerId === 'rocket-launches' ? 'space-missions' : null;
const deferredClearEntry = this._contextModeDeferredEntryIntent?.intentEpoch === change.intentEpoch;
const entryMode =
change.layerId === 'rocket-launches' ? 'space-missions' : null;
const deferredClearEntry =
this._contextModeDeferredEntryIntent?.intentEpoch ===
change.intentEpoch;
// A deferred entry owns the state after Clear settles. Restoring
// Clear's transient busy flag here would leave Context stuck.
const priorChanging = deferredClearEntry ? false : this._contextModeChanging;
const notificationToken = change.notificationToken || Symbol('direct-context-shell-entry');
const priorChanging = deferredClearEntry
? false
: this._contextModeChanging;
const notificationToken =
change.notificationToken || Symbol('direct-context-shell-entry');
const ownsNotificationToken = !change.notificationToken;
if (ownsNotificationToken) {
this._userFacingContextNotificationTokens.add(notificationToken);
@@ -80,10 +99,16 @@ export function connectContextManager(manager) {
if (deferredClearEntry) {
await this._clearSelectedLayersManagerPromise;
if (this.destroyed) return false;
if (this._contextModeDeferredEntryIntent?.intentEpoch !== change.intentEpoch) return false;
if (
this._contextModeDeferredEntryIntent?.intentEpoch !==
change.intentEpoch
)
return false;
this._contextModeDeferredEntryIntent = null;
}
await this._clearLayersOutsideContextMode(entryMode, { notificationToken });
await this._clearLayersOutsideContextMode(entryMode, {
notificationToken,
});
if (this.destroyed) return false;
} catch (error) {
this._contextModeEntering = null;
@@ -94,30 +119,37 @@ export function connectContextManager(manager) {
notificationToken,
});
} catch (restoreError) {
console.warn(`[Context] ${change.layerId} rollback failed`, restoreError);
console.warn(
`[Context] ${change.layerId} rollback failed`,
restoreError,
);
}
return `${entryMode === 'space-missions' ? 'Space Missions' : 'Context'} could not start because another layer did not stop cleanly`;
} finally {
if (ownsNotificationToken) {
this._userFacingContextNotificationTokens.delete(notificationToken);
this._userFacingContextNotificationTokens.delete(
notificationToken,
);
}
if (!this.destroyed) settleContextModeChange(this, priorChanging);
}
}
return null;
});
}
if (typeof this._dataManager?.subscribeBeforeDestroy === 'function') {
this._dataManagerBeforeDestroyUnsubscribe = this._dataManager.subscribeBeforeDestroy(async ({ layerId } = {}) => {
}
if (typeof this._dataManager?.subscribeBeforeDestroy === 'function') {
this._dataManagerBeforeDestroyUnsubscribe =
this._dataManager.subscribeBeforeDestroy(async ({ layerId } = {}) => {
if (this.destroyed || !this._contextSessionSnapshot) return;
await runWithContextModeChanging(this, async () => {
this._contextMode = null;
this.cockpitView?.exit({ restoreTracking: false });
this._syncContextModeButtons();
await this._restoreContextSession({ excludeLayerIds: layerId ? [layerId] : [] });
await this._restoreContextSession({
excludeLayerIds: layerId ? [layerId] : [],
});
});
});
}
}
this._syncContextModeButtons();
}