Skip to main content

Class: StatusUpdateManager

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

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({
fullSyncFromBackend: () => 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:274

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

cleanupFunctionsโ€‹

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

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

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.


fullSyncFromBackend()โ€‹

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

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

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

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

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: undefined | (update: StatusUpdate) => void

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

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

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

Internal

Handle incremental status updates efficiently without full sync.

Parametersโ€‹

eventโ€‹

MonitorStatusChangedEvent

Monitor status changed event data

Returnsโ€‹

Promise<void>

Remarksโ€‹

Applies status changes directly to existing site/monitor data in the store. This is much more efficient than triggering a full sync for every status change. Falls back to full sync only if the site/monitor cannot be found.


isSubscribed()โ€‹

isSubscribed(): boolean

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

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.


subscribe()โ€‹

subscribe(): void

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

Subscribe to status updates from the backend with efficient incremental processing.

Returnsโ€‹

void

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();

unsubscribe()โ€‹

unsubscribe(): void

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

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

manager.unsubscribe();
console.log(manager.isSubscribed()); // false

applyMonitorStatusUpdate()โ€‹

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

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

Internal

Apply monitor status update to sites array.

Parametersโ€‹

sitesโ€‹

Site[]

Current sites array

siteโ€‹

Site

Site containing the monitor

monitorโ€‹

Monitor

Monitor to update

eventโ€‹

MonitorStatusChangedEvent

Status change event

Returnsโ€‹

Site[]

Updated sites array


findMonitorInSite()โ€‹

private findMonitorInSite(site: Site, monitorId: string): undefined | Monitor

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

Internal

Find a monitor in a site by monitor ID.

Parametersโ€‹

siteโ€‹

Site

Site to search for monitor

monitorIdโ€‹

string

Monitor ID to find

Returnsโ€‹

undefined | Monitor

Monitor if found, undefined otherwise


findSiteInStore()โ€‹

private findSiteInStore(sites: Site[], siteId: string): undefined | Site

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

Internal

Find a site in the store by identifier.

Parametersโ€‹

sitesโ€‹

Site[]

Array of sites to search

siteIdโ€‹

string

Site identifier to find

Returnsโ€‹

undefined | Site

Site if found, undefined otherwise


isMonitorStatusChangedEvent()โ€‹

private isMonitorStatusChangedEvent(data: unknown): data is MonitorStatusChangedEvent

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

Internal

Type guard to validate incoming data as 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. This helps prevent runtime errors from malformed data.