readonly-stateflow-cold-to-hot

Installation
SKILL.md

Read-only exposure, and cold sources made hot

Two decisions, one property each. Both are one line, and both are routinely got wrong in a way that compiles and mostly works.

Exposure. A state holder is written by exactly one owner and read by everyone else, so the public type must be the read-only one:

// adapted — initial value trimmed
private val _controlState = MutableStateFlow(ControlState(...))
val controlState: StateFlow<ControlState> = _controlState.asStateFlow()

Cold to hot. A source flow — a preferences store, a database query — is cold: every collector starts its own read. Sharing it once, with a keep-alive window, gives every screen the same value and stops the upstream a beat after the last collector leaves:

Installs
2
GitHub Stars
35
First Seen
6 days ago
readonly-stateflow-cold-to-hot — maxrave-dev/kotlin-footguns