Class: StatusUpdateManager
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:119
Manages status update subscriptions and event handling with efficient incremental updates.
Remarksโ
Provides a centralized manager for subscribing to and handling real-time status updates from the backend. Handles IPC event management and cleanup automatically. Prioritizes incremental updates over full syncs for better performance.
Exampleโ
const manager = new StatusUpdateManager({
fullResyncSites: () => syncSites(),
getSites: () => store.getSites(),
setSites: (sites) => store.setSites(sites),
});
manager.subscribe();
Constructorsโ
Constructorโ
new StatusUpdateManager(
options:StatusUpdateHandlerOptions):StatusUpdateManager
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:461
Constructs a new StatusUpdateManager instance.
Parametersโ
optionsโ
Configuration options for the status update manager
Returnsโ
StatusUpdateManager
Remarksโ
Initializes the manager with the required dependencies for status update handling. Does not start listening for events until subscribe() is called.
Propertiesโ
EXPECTED_LISTENER_COUNTโ
readonlystaticEXPECTED_LISTENER_COUNT:4=4
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:121
Number of listeners required for a healthy subscription.
cleanupFunctionsโ
privatecleanupFunctions: () =>void[] =[]
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:133
Internal
Array of cleanup functions for active event listeners.
Returnsโ
void
Remarksโ
Stores cleanup functions returned by IPC event listeners. These are called during unsubscribe() to properly remove event listeners and prevent memory leaks. Each function removes a specific event listener.
fullResyncSites()โ
privatereadonlyfullResyncSites: () =>Promise<void>
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:145
Internal
Function to trigger full site data sync from backend.
Returnsโ
Promise<void>
Remarksโ
Callback function provided during construction that performs a complete refresh of site data from the backend. Used as fallback when incremental updates fail or when a full sync is required.
getSites()โ
privatereadonlygetSites: () =>Site[]
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:157
Internal
Function to get current sites from store.
Returnsโ
Site[]
Remarksโ
Callback function that returns the current array of sites from the store state. Used to access current data when applying incremental status updates.
isListenerAttachedโ
privateisListenerAttached:boolean=false
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:169
Internal
Flag tracking whether event listener is currently attached.
Remarksโ
Boolean flag that tracks the subscription state. True when IPC event listeners are active and receiving status updates. Used to prevent duplicate subscriptions and to provide subscription status.
onUpdateโ
privatereadonlyonUpdate: (update:StatusUpdate) =>void|undefined
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:181
Internal
Optional callback for status update notifications.
Remarksโ
Optional callback function that is invoked when a status update is successfully applied. Receives the StatusUpdate object with details about the change. Can be used for logging or triggering side effects.
setSites()โ
privatereadonlysetSites: (sites:Site[]) =>void
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:193
Internal
Function to update sites in the store.
Parametersโ
sitesโ
Site[]
Returnsโ
void
Remarksโ
Callback function that updates the store with a new array of sites. Used to apply incremental status updates and full sync results to the store state.
Methodsโ
handleIncrementalStatusUpdate()โ
privatehandleIncrementalStatusUpdate(event:MonitorStatusChangedEvent):Promise<void>
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:207
Internal
Handle incremental status updates efficiently using complete event data.
Parametersโ
eventโ
Monitor status changed event with complete data
Returnsโ
Promise<void>
Remarksโ
Applies status changes using the complete monitor and site objects from the backend event. This preserves the updated history and ensures check counts increment correctly while providing real-time updates.
attemptFullResync()โ
privateattemptFullResync(reason:string):Promise<void>
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:275
Attempts a full resync and guarantees the caller never throws.
Parametersโ
reasonโ
string
Returnsโ
Promise<void>
subscribe()โ
subscribe():
Promise<StatusUpdateSubscriptionResult>
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:302
Subscribe to status updates from the backend with efficient incremental processing.
Returnsโ
Promise<StatusUpdateSubscriptionResult>
Remarksโ
Sets up IPC event listeners for monitor status changes and monitoring lifecycle events. Automatically performs an initial full sync when subscribing. Prioritizes incremental updates over full syncs for better performance.
Exampleโ
manager.subscribe();
processStatusUpdateCandidate()โ
privateprocessStatusUpdateCandidate(candidate:unknown,source:string):Promise<void>
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:402
Process an unknown candidate payload that may represent an enriched monitor status change.
Parametersโ
candidateโ
unknown
sourceโ
string
Returnsโ
Promise<void>
Remarksโ
This method centralizes:
- Type guard checks
- Development diagnostics
- Fallback to full resync when payloads are incomplete
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Error containment so listener callbacks never throw
recordSubscriptionError()โ
privaterecordSubscriptionError(errors:string[],scope:string,error:unknown):Error
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:441
Records a subscription-related error in a consistent format.
Parametersโ
errorsโ
string[]
scopeโ
string
errorโ
unknown
Returnsโ
Remarksโ
The returned error instance is the normalized https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Error so callers can reuse it for structured logging.
getExpectedListenerCount()โ
getExpectedListenerCount():
number
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:473
Retrieves the expected listener count for diagnostics.
Returnsโ
number
Number of listeners the manager attempts to attach.
isSubscribed()โ
isSubscribed():
boolean
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:485
Check if currently subscribed to status updates.
Returnsโ
boolean
True if subscribed and listening for events, false otherwise
Remarksโ
Returns true when event listeners are active.
unsubscribe()โ
unsubscribe():
void
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:507
Unsubscribe from all status update events.
Returnsโ
void
Remarksโ
Cleans up all IPC event listeners and resets internal state. Safe to call multiple times - will not throw if already unsubscribed.
Exampleโ
import { logger } from "@app/services/logger";
manager.unsubscribe();
logger.info("Subscription active?", {
isSubscribed: manager.isSubscribed(),
}); // false
handleMonitoringLifecycleEvent()โ
Call Signatureโ
privatehandleMonitoringLifecycleEvent(phase:"started",event:MonitoringStartedEventData):void
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:528
Parametersโ
phaseโ
"started"
eventโ
Returnsโ
void
Call Signatureโ
privatehandleMonitoringLifecycleEvent(phase:"stopped",event:MonitoringStoppedEventData):void
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:533
Parametersโ
phaseโ
"stopped"
eventโ
Returnsโ
void
applyMonitorStatusUpdate()โ
privateapplyMonitorStatusUpdate(sites:Site[],event:MonitorStatusChangedEvent):Site[]
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:587
Internal
Apply monitor status update using smart merging of fresh monitor data.
Parametersโ
sitesโ
Site[]
Current sites array
eventโ
Status change event with fresh monitor data
Returnsโ
Site[]
Updated sites array
Remarksโ
Uses the fresh monitor object from the backend event to update the specific monitor while preserving the existing site structure and other monitors. This ensures updated history and response times are applied without losing site-level context.
isMonitorStatusChangedEvent()โ
privateisMonitorStatusChangedEvent(data:unknown):data is MonitorStatusChangedEvent
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:609
Internal
Type guard to validate incoming data as complete MonitorStatusChangedEvent.
Parametersโ
dataโ
unknown
Unknown data from IPC events
Returnsโ
data is MonitorStatusChangedEvent
True if data conforms to MonitorStatusChangedEvent interface
Remarksโ
Performs structural validation to ensure the data has the expected shape for incremental processing with complete monitor and site objects. This helps prevent runtime errors from malformed data.