Skip to content

Commit 9973936

Browse files
Merge pull request #1341 from square/sedwards/move-render-context
1340: Changing `RenderContext` from an inner class to a nested class with its own generics
2 parents bf75158 + bd4480b commit 9973936

File tree

59 files changed

+139
-149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+139
-149
lines changed

benchmarks/performance-poetry/complex-poetry/src/main/java/com/squareup/benchmarks/performance/complex/poetry/MaybeLoadingGatekeeperWorkflow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class MaybeLoadingGatekeeperWorkflow<T : Any>(
2727
override fun render(
2828
renderProps: Unit,
2929
renderState: IsLoading,
30-
context: RenderContext
30+
context: RenderContext<Unit, IsLoading, Unit>
3131
): MayBeLoadingScreen {
3232
context.runningWorker(isLoading.asTraceableWorker("GatekeeperLoading")) {
3333
action("GatekeeperLoading") {

benchmarks/performance-poetry/complex-poetry/src/main/java/com/squareup/benchmarks/performance/complex/poetry/PerformancePoemWorkflow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class PerformancePoemWorkflow(
9696
override fun render(
9797
renderProps: Poem,
9898
renderState: State,
99-
context: RenderContext
99+
context: RenderContext<Poem, State, ClosePoem>
100100
): OverviewDetailScreen<*> {
101101
if (simulatedPerfConfig.simultaneousActions > 0) {
102102
repeat(simulatedPerfConfig.simultaneousActions) { index ->

benchmarks/performance-poetry/complex-poetry/src/main/java/com/squareup/benchmarks/performance/complex/poetry/PerformancePoemsBrowserWorkflow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class PerformancePoemsBrowserWorkflow(
8686
override fun render(
8787
renderProps: ConfigAndPoems,
8888
renderState: State,
89-
context: RenderContext
89+
context: RenderContext<ConfigAndPoems, State, Unit>
9090
): OverviewDetailScreen<*> {
9191
when (renderState) {
9292
is Recurse -> {

design-docs/compose-based-workflows-design.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ A more interesting, comprehensive example that ties this in with the First Primi
282282
```kotlin
283283
class IdentityWorkflow(
284284
private val child: Workflow<Props, Output, Rendering>
285-
) : StatelessWorkflow<Props, Output, Rendering {
285+
) : StatelessWorkflow<Props, Output, Rendering> {
286286
override fun render(props: Props, context: RenderContext): Rendering {
287287
return context.renderComposable {
288288
renderWorkflow(child, props, onOutput = { output ->
@@ -379,8 +379,7 @@ public abstract class ComposeWorkflow<
379379
To implement the `Workflow` interface, we need to have a function that returns a `StatefulWorkflow` with the actual implementation. That's trivial: we just return a really simple workflow that does nothing but call `renderComposable` from above in its render method:
380380

381381
```kotlin
382-
private inner class ComposeWorkflowWrapper :
383-
StatefulWorkflow<PropsT, Unit, OutputT, RenderingT>() {
382+
inner class ComposeWorkflowWrapper : StatefulWorkflow<PropsT, Unit, OutputT, RenderingT>() {
384383

385384
override fun initialState(
386385
props: PropsT,
@@ -392,7 +391,7 @@ To implement the `Workflow` interface, we need to have a function that returns a
392391
override fun render(
393392
renderProps: PropsT,
394393
renderState: Unit,
395-
context: RenderContext
394+
context: StatefulWorkflow.RenderContext<PropsT,Unit,OutputT>
396395
): RenderingT = context.renderComposable {
397396
// Explicitly remember the output function since we know that actionSink
398397
// is stable even though Compose might not know that.

samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocompose/HelloComposeWorkflow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ object HelloComposeWorkflow : StatefulWorkflow<Unit, State, Nothing, HelloCompos
3232
override fun render(
3333
renderProps: Unit,
3434
renderState: State,
35-
context: RenderContext
35+
context: RenderContext<Unit, State, Nothing>
3636
): HelloComposeScreen = HelloComposeScreen(
3737
message = renderState.name,
3838
onClick = { context.actionSink.send(helloAction) }

samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposebinding/HelloWorkflow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ object HelloWorkflow : StatefulWorkflow<Unit, State, Nothing, Rendering>() {
3939
override fun render(
4040
renderProps: Unit,
4141
renderState: State,
42-
context: RenderContext
42+
context: RenderContext<Unit, State, Nothing>
4343
): Rendering {
4444
return Rendering(
4545
message = renderState.name,

samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposeworkflow/ComposeWorkflowImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ internal class ComposeWorkflowImpl<PropsT, OutputT : Any>(
5959
override fun render(
6060
renderProps: PropsT,
6161
renderState: State<PropsT, OutputT>,
62-
context: RenderContext
62+
context: RenderContext<PropsT, State<PropsT, OutputT>, OutputT>
6363
): ComposeScreen {
6464
// The first render pass needs to cache the sink. The sink is reusable, so we can just pass the
6565
// same one every time.

samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposeworkflow/HelloWorkflow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ object HelloWorkflow : StatefulWorkflow<Unit, State, Nothing, ComposeScreen>() {
3737
override fun render(
3838
renderProps: Unit,
3939
renderState: State,
40-
context: RenderContext
40+
context: RenderContext<Unit, State, Nothing>
4141
): ComposeScreen =
4242
context.renderChild(HelloComposeWorkflow, renderState.name) { helloAction }
4343

samples/compose-samples/src/main/java/com/squareup/sample/compose/inlinerendering/InlineRenderingWorkflow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ object InlineRenderingWorkflow : StatefulWorkflow<Unit, Int, Nothing, Screen>()
3535
override fun render(
3636
renderProps: Unit,
3737
renderState: Int,
38-
context: RenderContext
38+
context: RenderContext<Unit, Int, Nothing>
3939
): ComposeScreen {
4040
val onClick = context.eventHandler("increment") { state += 1 }
4141
return ComposeScreen {

samples/compose-samples/src/main/java/com/squareup/sample/compose/nestedrenderings/RecursiveWorkflow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ object RecursiveWorkflow : StatefulWorkflow<Unit, State, Nothing, Screen>() {
5757
override fun render(
5858
renderProps: Unit,
5959
renderState: State,
60-
context: RenderContext
60+
context: RenderContext<Unit, State, Nothing>
6161
): Rendering {
6262
return Rendering(
6363
children = List(renderState.children) { i ->

0 commit comments

Comments
 (0)