trevjones
11/21/2022, 6:31 PMCLOVIS
11/22/2022, 4:41 PMCLOVIS
11/22/2022, 4:42 PMtrevjones
11/22/2022, 4:42 PMCLOVIS
11/22/2022, 4:43 PMtrevjones
11/22/2022, 4:43 PMCLOVIS
11/22/2022, 4:45 PMprovidesDefault
in your component? This way if the caller forgot to provide one, there is still onetrevjones
11/22/2022, 4:46 PMCLOVIS
11/22/2022, 4:46 PMtrevjones
11/22/2022, 4:47 PMCLOVIS
11/22/2022, 4:48 PMtrevjones
11/22/2022, 4:52 PMtrevjones
11/22/2022, 4:53 PMCLOVIS
11/22/2022, 4:53 PMtrevjones
11/22/2022, 4:57 PMsetContent
so it will default to our default theme if you forget to overload the JV theme lookup.
but I don’t love that either because it leaves a gap where if you mess up on which base class to use you can end up in a situation where it would fail to the default theme rather than blow up.
trying to balance the ergonomics of it all with correctness really.
the idea of arrow being able to explode in a CI build with missing CompLocal’s seemed really cool. Plus having maybe eventual IDE tooling where you could do like the CMD+P and it would also list what CompLocals are used internally would be probably useful.CLOVIS
11/22/2022, 5:52 PMCLOVIS
11/22/2022, 5:53 PMtrevjones
11/22/2022, 6:01 PMobject LocalAnalytics {
private val local = staticCompositionLocalOf<Analytics?> { null }
val current: Analytics
@Composable
@ReadOnlyComposable
get() {
val current = local.current
return checkNotNull(current) { "useful message omitted" }
}
infix fun provides(registry: Analytics): ProvidedValue<Analytics?> = local.provides(registry)
}
then elsewhere you just do a LocalAnalytics.current
which in this case is all inside of composed modifiers.
CompositionLocal<T>
has a val current: T
so i’d expect it would look for reads of that current: T
to build the list of what is used. if T
is nullable maybe treat it as optional. then analyze the call site to see what ProvidableCompositionLocal<T>.provides[Default]
usages have been used in your call stack. warning for missing T?
locals and errors missing T
’s