Sean McQuillan [G]
09/25/2020, 9:02 PMVinay Gaba
09/25/2020, 9:06 PMRicardo C.
09/25/2020, 9:15 PMAdam Powell
09/25/2020, 9:16 PMAdam Powell
09/25/2020, 9:17 PMSean McQuillan [G]
09/25/2020, 9:17 PMAdam Powell
09/25/2020, 9:20 PMAdam Powell
09/25/2020, 9:21 PMSean McQuillan [G]
09/25/2020, 9:21 PMZach Klippenstein (he/him) [MOD]
09/25/2020, 9:43 PMSean McQuillan [G]
09/25/2020, 9:45 PMAdam Powell
09/25/2020, 9:48 PMAdam Powell
09/25/2020, 9:48 PMAdam Powell
09/25/2020, 9:57 PMVinay Gaba
09/25/2020, 10:27 PMColton Idle
09/26/2020, 1:57 AMMy personal style is to limit interaction with DI to a single composable and provide injection via parameters (parameters to composable are very similar to ctor arguments to a class). This makes it easy for tests to specialize any parameter, and avoids mixing DI with the rest of the code.Why would someone not want to do that?
gildor
09/26/2020, 3:05 AMJavier
09/26/2020, 9:01 AMgildor
09/26/2020, 9:11 AMgildor
09/26/2020, 9:16 AMgildor
09/26/2020, 9:24 AMmzgreen
09/26/2020, 9:51 AMJavier
09/26/2020, 10:10 AMraulraja
09/26/2020, 3:02 PMraulraja
09/26/2020, 3:04 PMraulraja
09/26/2020, 3:06 PMraulraja
09/26/2020, 3:12 PMAdam Powell
09/26/2020, 3:26 PMAdam Powell
09/26/2020, 3:28 PMraulraja
09/26/2020, 4:05 PMinterface fun Persist<A> { fun A.save() }
data class User
@Extension fun User.persist(): Persist<User> = Persist { ... }
User().save() //all members of Persist are projected over User and this desugars to User().persist().save() in IR
raulraja
09/26/2020, 4:10 PMraulraja
09/26/2020, 4:11 PMVinay Gaba
09/26/2020, 5:06 PMraulraja
09/26/2020, 6:09 PMAdam Powell
09/26/2020, 6:10 PMAdam Powell
09/26/2020, 6:12 PMcarbaj0
09/26/2020, 6:13 PMraulraja
09/26/2020, 6:17 PMEmployee.company.address.street.name
with the compiler plugin over any recursive datastructure solving the nested copy and focus problem including sealed hierarchies. @carbaj0 Iโm actually speaking with Leland in the Kotlin London round table coming up soon, not sure if already announced ๐raulraja
09/26/2020, 6:21 PMAdam Powell
09/26/2020, 6:21 PMraulraja
09/26/2020, 6:23 PMAdam Powell
09/26/2020, 6:24 PMAdam Powell
09/26/2020, 6:25 PMDavide Giuseppe Farella
09/26/2020, 7:53 PMraulraja
09/26/2020, 8:37 PMDavide Giuseppe Farella
09/26/2020, 9:04 PMraulraja
09/26/2020, 10:39 PMDavide Giuseppe Farella
09/26/2020, 11:10 PMraulraja
09/26/2020, 11:38 PMSean McQuillan [G]
09/27/2020, 11:47 PM@Composable
fun App() {
val myService = get<MyService>()
// or val myService by inject<MyService>()
}
This can be transformed to a parameter by using a default argument:
@Composable
fun App(myService: MyService = get()) {
}
By lifting it from a local variable (equivalent to property injection) to a parameter (equivalent to constructor injection) it's easier to work with in other situations like tests. It also has the advantage of making the calling contract explicit (internal calls to get
are hidden form the caller of App
)
To be concrete, that has a similar calling contract executes similarly to this constructor spelling:
class App(val myService: MyService = get()) {
@Composable
fun compose() { }
}
This is definitely an area where I expect more iteration as we get more experience developing in Compose. Very educational reading all of the thoughts here!Sean McQuillan [G]
09/27/2020, 11:55 PMSean McQuillan [G]
09/28/2020, 12:55 AM@Composable
fun App(myService: MyService) {}
val App: @Composable () -> Unit = ::App(get())
(Note: This code doesn't compile today ๐ )gildor
09/28/2020, 2:10 AMSean McQuillan [G]
09/28/2020, 5:58 AMarnaud.giuliani
09/28/2020, 9:53 AM@Composable
fun App(myService: MyService = get()) {
}