In my ViewModel I’ve implemented couple of functions to manipulate the state of my UI. It quickly becomes bigger and bigger and I wonder if these functions violate the DRY principle? I could wrap it all in a single function, but on the other hand the function would be a lot more complex and harder to test. What is the best solution here?
val inputState = _inputState.asStateFlow()
fun updateInputStateTitle(title: String) {
_inputState.update {
it.copy(title = title)
}
}
fun updateInputStateCharacterCounterTitle(characterCounter: Int) {
_inputState.update {
it.copy(characterCounterTitle = characterCounter)
}
}
fun updateInputStateDescription(description: String) {
_inputState.update {
it.copy(description = description)
}
}
fun updateInputStateCharacterCounterDescription(characterCounter: Int) {
_inputState.update {
it.copy(characterCounterDescription = characterCounter)
}
}
fun updateInputStateCategory(category: String) {
_inputState.update {
it.copy(category = category)
}
}
fun updateInputStateCharacterCounterCategory(characterCounter: Int) {
_inputState.update {
it.copy(characterCounterCategory = characterCounter)
}
}
fun updateInputStateDeadline(deadline: String) {
_inputState.update {
it.copy(deadline = deadline)
}
}
fun updateInputStateCharacterCounterDeadline(characterCounter: Int) {
_inputState.update {
it.copy(characterCounterDeadline = characterCounter)
}
}