Skip to content

Added container with ext state option #224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

Rosomack
Copy link
Contributor

A pattern that we often see is that as a ContainerHost grows in complexity, a lot of the Container's state may exist only to track the ContainerHost's state.

Essentially as we're mixing internal and external (e.g. UI) state it becomes increasingly taxing to hoist the UI state out of the container's state.

This PR introduces an optional ContainerHostWithExtState and ContainerWithExtState that introduce a simple mapping layer and expose extStateFlow for collection in the UI. We take the internal state and apply the mapper in order to turn it into an external state. All you need to do as the dev is to implement this mapper.

public override val settings: RealSettings,
subscribedCounterOverride: SubscribedCounter? = null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to hoist these params to the RealSettings so that we could use the refcount extension on the ext state flow. I didn't want to expose the subscribedCounter on Container as it would just pollute the API surface.

This was painful, and I'm not entirely happy with the RealSettings class the way it's defined currently, but it was necessary.

@Rosomack Rosomack marked this pull request as draft May 23, 2025 11:46
@@ -134,14 +145,11 @@ class CalculatorViewModel(savedStateHandle: SavedStateHandle) : ViewModel() {
}

@Parcelize
private data class CalculatorStateImpl(
data class InternalCalculatorState(
Copy link
Contributor

@mattmook mattmook May 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This single line highlights one of the biggest downsides with ContainerHostWithExtState, suddenly your internal state types are all public.

i can't see any obvious way around this though

@Rosomack
Copy link
Contributor Author

Rosomack commented Jul 3, 2025

#294 supersedes this

@Rosomack Rosomack closed this Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants