Class: StatusUpdateManager
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:219
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:598
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:221
Number of listeners required for a healthy subscription.
cleanupFunctionsโ
privatecleanupFunctions: () =>void[] =[]
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:233
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:245
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:257
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:269
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:281
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:293
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:307
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.
subscribe()โ
subscribe():
Promise<StatusUpdateSubscriptionResult>
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:383
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();
getExpectedListenerCount()โ
getExpectedListenerCount():
number
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:610
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:622
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:644
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:MonitoringControlEventData& {monitorCount:number;siteCount:number;summary?:MonitoringStartSummary; }):void
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:655
Parametersโ
phaseโ
"started"
eventโ
MonitoringControlEventData & { monitorCount: number; siteCount: number; summary?: MonitoringStartSummary; }
Returnsโ
void
Call Signatureโ
privatehandleMonitoringLifecycleEvent(phase:"stopped",event:MonitoringControlEventData& {activeMonitors:number;reason:MonitoringControlReason;summary?:MonitoringStopSummary; }):void
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:660
Parametersโ
phaseโ
"stopped"
eventโ
MonitoringControlEventData & { activeMonitors: number; reason: MonitoringControlReason; summary?: MonitoringStopSummary; }
Returnsโ
void
applyMonitorStatusUpdate()โ
privateapplyMonitorStatusUpdate(sites:Site[],event:MonitorStatusChangedEvent):Site[]
Defined in: src/stores/sites/utils/statusUpdateHandler.ts:710
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:732
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.