workflow-kotlin icon indicating copy to clipboard operation
workflow-kotlin copied to clipboard

Wrapping still is a pain, and losing type info from Screen.withEnvironment is too.

Open rjrjr opened this issue 3 years ago • 1 comments
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>

rjrjr avatar Feb 23 '22 19:02 rjrjr

VisualFactory to be introduced with #874 should address this.

rjrjr avatar Sep 15 '22 17:09 rjrjr

  • VisualFactory was abandoned, long live #1146
  • Most of this pain has been addressed by the Container and Wrapper types.

rjrjr avatar Dec 19 '23 02:12 rjrjr