DEV Community
Follow
Keeping a Bubble Tea Dashboard in Sync with soroi
An incident console with multiple panes presents challenges in data management. The soroi library for Go addresses these by providing a typed query client. It allows multiple components to read the same remote data, ensuring data consistency and efficient caching.Each pane, such as the incident list, detail, and summary, can subscribe to the same shared data using a single soroi client. This client manages overlapping data loads, reusing fresh results and avoiding redundant requests. Data is kept read-only in the cache, with writes routed through a service.A bridge connects soroi's query subscriptions to Bubble Tea, allowing UI updates through messages. Each pane receives snapshot updates, ensuring the UI reflects the latest query state. This approach prevents direct model manipulation from background goroutines.The system handles refresh failures gracefully by displaying the last known data and an error message. It differentiates between initial load failures and subsequent refresh failures. Incident acknowledgements are handled as asynchronous commands, preventing UI freezes.Upon a successful acknowledgement, the shared queue is invalidated, triggering a refresh for all active observers. The panes display stale data during the refresh, then update with the new owner. Incident selection is ID-based, preventing accidental acknowledgements after a queue reorder.Resource cleanup is crucial; the client and query handles are released upon terminal exit. This pattern is ideal for terminal tools where components read shared remote data with independent lifetimes.