Fix debloater component state update#1370
Merged
Merged
Conversation
Refactor DebloaterViewModel to use cached data with reactive updates. This ensures component toggle switches update immediately when enabling/disabling components while still observing database changes. Changes: - Use MutableStateFlow for manual state management - Cache debloatable entities to avoid repeated repository queries - Observe database flow for real-time updates - Update cache during optimistic updates to prevent stale state - Extract filter/search logic into reusable applyFiltersAndUpdate() The component state now updates instantly when toggled, and the UI automatically refreshes when database changes occur elsewhere.
274fd5b to
54c7a56
Compare
Change-Id: Idb4e8cc9fc973d85fbdd06f29fa352376a157f11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes component toggle switches not updating immediately in UI when enabling/disabling components in the debloater module.
Problem
When toggling a component that was previously disabled, the UI switch did not update immediately. The state only reflected correctly after restarting the app.
Root cause: The original implementation used optimistic updates, but the underlying database flow would re-emit old data and overwrite the optimistic UI changes.
Solution
Refactored
DebloaterViewModelto use a cached data approach with reactive updates:cachedEntities)This approach provides:
Key Changes
File:
feature/debloater/src/main/kotlin/com/merxury/blocker/feature/debloater/DebloaterViewModel.ktcachedEntitiesfield to store complete datasetloadData()to observe database flow and update cacheapplyFiltersAndUpdate()to centralize filter/search logicchangeDebloatableComponentUiStatus()to update both cache and UIImplementation Pattern
This differs from
RuleDetailViewModelwhich uses one-time data loading:.first(), no auto-refresh.collect{}, auto-refreshesThe debloater pattern is more appropriate here because:
Testing
Test Plan