adjpd
08/21/2022, 3:17 AMStylianos Gakis
08/21/2022, 12:43 PMadjpd
08/21/2022, 4:56 PMStylianos Gakis
08/21/2022, 10:56 PMadjpd
08/21/2022, 10:58 PMStylianos Gakis
08/21/2022, 11:00 PMadjpd
08/22/2022, 4:13 PMStylianos Gakis
08/22/2022, 10:30 PMfun composable(stateLocal: MyCompositionLocal = DefaultMyCompositionLocal)
? Or how does it look like?adjpd
08/22/2022, 10:41 PMfun composable(someState: String = DefaultMyCompositionLocal.current.someState) {
}
I do a similar thing with methods in my state objects/event objects.Stylianos Gakis
08/23/2022, 7:46 AMSomeState
object down the tree instead of SomeStateCompositionLocal
then? I don’t see what you gain from the CompositionLocal.
Plus the problems that I mentioned above still exist, with potentially the composables not being in the correct part of the tree where your Composition local is not provided and getting a runtime crash instead of a compile-time one, or providing multiple ones down different parts of the tree and getting subtle bugs and so on.
The fact that it’s something that may happen in SwiftUI doesn’t mean it’s good to replicate here as well imo.adjpd
08/23/2022, 5:16 PMdefineCompLocal {
comp2()
}
fun comp2() {
comp3()
}
fun comp3(state = compLocal.current.state) {
// use state
}
instead of
var state = "something"
comp2(state)
comp2(state) {
comp3(state)
}
comp3(state) {
//finally use state
}
Yeah you need the comp locals to be in the correct tree yeah, but my comp locals are at the root, so no real problem.
If you hate it, that's fine my friend!Stylianos Gakis
08/23/2022, 5:31 PM