allan.conda
09/03/2020, 6:39 AMTextField
is stateless, but TextFieldImpl
as a bunch of mutable states internally. How do we know if a Composable is stateless or not?Adam Powell
09/03/2020, 1:24 PMAdam Powell
09/03/2020, 1:25 PMSean McQuillan [G]
09/06/2020, 8:33 PMSean McQuillan [G]
09/06/2020, 8:34 PMSean McQuillan [G]
09/06/2020, 8:37 PMTextField
– the actual state management is a more complex than a simple statefull/stateless division (though the same analysis applies – TextField is more complex due to it's internal state). The goal of that was to teach practical state hoisting techniques as that's the big change moving to declarative.
We're also finding with TextField
and similar composables we've built that have duplicated state this can be a double edged sword as the duplicated state introduces the ability of update errors.
Currently in TextField
if you back the text state with an async updated state holder, it's possible to show characters before they're applied, or even drop characters. As Adam said some more work is coming on this particular API.Sean McQuillan [G]
09/06/2020, 8:41 PMSean McQuillan [G]
09/06/2020, 8:53 PMTextField
also provides an override that allows you to hoist the edit text state completely. This API was avoided in the codelab since ergonomics of this API require hosting a data class and introduced a bunch of unrelated and likely-to-be-changed concepts.Sean McQuillan [G]
09/17/2020, 8:33 PMA stateless composable with respect to a particular state cannot directly change that state.
A stateful composable with respect to a particular state can directly change that state.
I'd love input on this!Sean McQuillan [G]
09/17/2020, 8:34 PMallan.conda
09/18/2020, 10:55 AMallan.conda
09/18/2020, 11:09 AMBuilt-in composable are designed using unidirectional data flow, and aims to be stateless.
A stateless composable does not own state and cannot change directly, and pushes up events to the owner of state that can change it.
A stateful composable maintain a lot of internal state and can change them directly.
(<if actually stateless as defined above> Most built-in composables are stateless.) Some built-in composables may own state for convenience, such as the TextField's cursor state so consumers do not always have to manually handle them.
I may be wrong about the built-in composables 🙂
Stateless should purely mean “does not own state” imo.
Stateful is more subjective (maybe a composable should not be considered stateful if it only maintains a single simple state)Sean McQuillan [G]
09/18/2020, 6:27 PMSean McQuillan [G]
09/18/2020, 6:28 PMSean McQuillan [G]
09/18/2020, 6:28 PMallan.conda
09/19/2020, 9:34 AM