Tash
03/16/2022, 10:56 PMwebView.goBackward()/webView.goForward()
, how do you encode them as state? They’re very event-like and need to happen just once given certain conditions, and could get complicated when state objects are `data class`es and you use .copy
to update parts of state. More in 🧵Tash
03/16/2022, 11:02 PMdata class State(val goBackInWebView: Boolean, val buttonColor: Color)
You might do something like:
// business logic change
state.copy(goBackInWebView = true) // setting it to true
// theme change
state.copy(buttonColor = Red) // goBackInWebView is still true
The first line causes goBackInWebView
to be true, but after the second line, you might read the state where goBackInWebView
is still true. Setting goBackInWebView = false
in the second line where you’re changing a part of the state in response to a theme change only is weird.
OR: are `data class`es a bad option in this case, and a sealed class
is better? Not sure what that would look like but something like
sealed class State {
data class ColorChanged(val buttonColor: Color): State()
object WebViewBack: State()
}
Ben Trengrove [G]
03/17/2022, 3:47 AMTash
03/17/2022, 5:36 AM