Skip to main content

Class: StatusUpdateManager

Defined in: src/stores/sites/utils/statusUpdateHandler.ts:117

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:424

Constructs a new StatusUpdateManager instance.

Parametersโ€‹

optionsโ€‹

StatusUpdateHandlerOptions

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โ€‹

readonly static EXPECTED_LISTENER_COUNT: 4 = 4

Defined in: src/stores/sites/utils/statusUpdateHandler.ts:119

Number of listeners required for a healthy subscription.


cleanupFunctionsโ€‹

private cleanupFunctions: () => void[] = []

Defined in: src/stores/sites/utils/statusUpdateHandler.ts:131

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()โ€‹

private readonly fullResyncSites: () => Promise<void>

Defined in: src/stores/sites/utils/statusUpdateHandler.ts:143

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()โ€‹

private readonly getSites: () => Site[]

Defined in: src/stores/sites/utils/statusUpdateHandler.ts:155

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โ€‹

private isListenerAttached: boolean = false

Defined in: src/stores/sites/utils/statusUpdateHandler.ts:167

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โ€‹

private readonly onUpdate: (update: StatusUpdate) => void | undefined

Defined in: src/stores/sites/utils/statusUpdateHandler.ts:179

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()โ€‹

private readonly setSites: (sites: Site[]) => void

Defined in: src/stores/sites/utils/statusUpdateHandler.ts:191

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()โ€‹

private handleIncrementalStatusUpdate(event: MonitorStatusChangedEvent): Promise<void>

Defined in: src/stores/sites/utils/statusUpdateHandler.ts:205

Internal

Handle incremental status updates efficiently using complete event data.

Parametersโ€‹

eventโ€‹

MonitorStatusChangedEvent

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:286

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()โ€‹

private processStatusUpdateCandidate(candidate: unknown, source: string): Promise<void>

Defined in: src/stores/sites/utils/statusUpdateHandler.ts:382

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:


getExpectedListenerCount()โ€‹

getExpectedListenerCount(): number

Defined in: src/stores/sites/utils/statusUpdateHandler.ts:436

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:448

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:470

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โ€‹

private handleMonitoringLifecycleEvent(phase: "started", event: MonitoringStartedEventData): void

Defined in: src/stores/sites/utils/statusUpdateHandler.ts:481

Parametersโ€‹
phaseโ€‹

"started"

eventโ€‹

MonitoringStartedEventData

Returnsโ€‹

void

Call Signatureโ€‹

private handleMonitoringLifecycleEvent(phase: "stopped", event: MonitoringStoppedEventData): void

Defined in: src/stores/sites/utils/statusUpdateHandler.ts:486

Parametersโ€‹
phaseโ€‹

"stopped"

eventโ€‹

MonitoringStoppedEventData

Returnsโ€‹

void


applyMonitorStatusUpdate()โ€‹

private applyMonitorStatusUpdate(sites: Site[], event: MonitorStatusChangedEvent): Site[]

Defined in: src/stores/sites/utils/statusUpdateHandler.ts:536

Internal

Apply monitor status update using smart merging of fresh monitor data.

Parametersโ€‹

sitesโ€‹

Site[]

Current sites array

eventโ€‹

MonitorStatusChangedEvent

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()โ€‹

private isMonitorStatusChangedEvent(data: unknown): data is MonitorStatusChangedEvent

Defined in: src/stores/sites/utils/statusUpdateHandler.ts:558

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.