https://kotlinlang.org logo
#android-architecture
Title
# android-architecture
u

ursus

03/16/2021, 2:36 AM
Single State people, how do you treat private vals? Do you remap to public? Or just not care? (Exposing integer counter to anyone is useless and it should be basically be just a boolean for anyone else) I know I can have private val on data class, but I cannot obviously increment it, etc
f

fal

03/17/2021, 5:37 PM
I would try to avoid having that counter in the state class then. Does it really need to be in state? Can you find a way to use it locally? It seems that the purpose there is simply to check if a sync is happening. But if that's the only purpose then there's some questions to address: • Why do you allow to sync again while a sync is already on-going? Is it acceptable to simply not allow this? (It seems that is the purpose of the counter, to keep track of concurrent syncs) • If you have to allow new syncs while another is happening, is there any way you cancel the previous one? If one of both solutions is acceptable, you can forego the counter, since in that case you can just set the state to the boolean solution directly. As a general rule (but I won't say that there's no absolute exceptions), I would probably say that if you feel the need to use private vals on state, it probably shouldn't be there in the first place.
2 Views