workflow-kotlin
workflow-kotlin copied to clipboard
Wrapping still is a pain, and losing type info from Screen.withEnvironment is too.
trafficstars
From a long discussion w/ @RBusarow
How about this:
sealed interface Screen
@WorkflowUiExperimentalApi
interface Screen_2 : Screen
@WorkflowUiExperimentalApi
class EnvironmentScreen<V : Screen_2> @PublishedApi internal constructor(
public val screen: V,
public val viewEnvironment: ViewEnvironment = ViewEnvironment.EMPTY
) : Compatible, Screen {
/* ... */
}
or this:
sealed interface Screen {
val environment : ViewEnvironment get() = EMPTY
interface LeafScreen : Screen
abstract class <S> ContainerScreen<S, C: ContainerScreen<S, C>>(
val children: List<S>,
): Screen {
abstract val environment: ViewEnvironment
abstract fun withEnvironment(e: Environment): C
}
}
class EnvironmentScreen<S: Screen>(
val wrapped: S,
override val environment: ViewEnvironment
) : ContainerScreen<S, EnvironmentScreen<S>>(listOf(wrapped), environment) {
override fun withEnvironment(e: Environment): EnvironmentScreen<S> {
return ...
}
}
fun <S: Screen> S.withEnvironment(e: ViewEnvironment): EnvironmentScreen<S>
VisualFactory to be introduced with #874 should address this.
VisualFactorywas abandoned, long live #1146- Most of this pain has been addressed by the
ContainerandWrappertypes.