diff --git a/benchmarks/performance-poetry/complex-poetry/src/main/java/com/squareup/benchmarks/performance/complex/poetry/MaybeLoadingGatekeeperWorkflow.kt b/benchmarks/performance-poetry/complex-poetry/src/main/java/com/squareup/benchmarks/performance/complex/poetry/MaybeLoadingGatekeeperWorkflow.kt index d6c64532ec..c0bd0fe6e7 100644 --- a/benchmarks/performance-poetry/complex-poetry/src/main/java/com/squareup/benchmarks/performance/complex/poetry/MaybeLoadingGatekeeperWorkflow.kt +++ b/benchmarks/performance-poetry/complex-poetry/src/main/java/com/squareup/benchmarks/performance/complex/poetry/MaybeLoadingGatekeeperWorkflow.kt @@ -8,6 +8,7 @@ import com.squareup.sample.container.overviewdetail.OverviewDetailScreen import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow import com.squareup.workflow1.Workflow +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.runningWorker import com.squareup.workflow1.ui.WorkflowUiExperimentalApi @@ -23,7 +24,8 @@ class MaybeLoadingGatekeeperWorkflow( ) : StatefulWorkflow() { override fun initialState( props: Unit, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): IsLoading = false override fun render( diff --git a/benchmarks/performance-poetry/complex-poetry/src/main/java/com/squareup/benchmarks/performance/complex/poetry/PerformancePoemWorkflow.kt b/benchmarks/performance-poetry/complex-poetry/src/main/java/com/squareup/benchmarks/performance/complex/poetry/PerformancePoemWorkflow.kt index 1a33e909f0..601c3fa405 100644 --- a/benchmarks/performance-poetry/complex-poetry/src/main/java/com/squareup/benchmarks/performance/complex/poetry/PerformancePoemWorkflow.kt +++ b/benchmarks/performance-poetry/complex-poetry/src/main/java/com/squareup/benchmarks/performance/complex/poetry/PerformancePoemWorkflow.kt @@ -30,6 +30,7 @@ import com.squareup.workflow1.StatefulWorkflow import com.squareup.workflow1.Worker import com.squareup.workflow1.WorkflowAction import com.squareup.workflow1.WorkflowAction.Companion.noAction +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.runningWorker import com.squareup.workflow1.ui.Screen @@ -84,7 +85,8 @@ class PerformancePoemWorkflow( override fun initialState( props: Poem, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): State { return if (simulatedPerfConfig.useInitializingState) { Initializing diff --git a/benchmarks/performance-poetry/complex-poetry/src/main/java/com/squareup/benchmarks/performance/complex/poetry/PerformancePoemsBrowserWorkflow.kt b/benchmarks/performance-poetry/complex-poetry/src/main/java/com/squareup/benchmarks/performance/complex/poetry/PerformancePoemsBrowserWorkflow.kt index 5d8aa9af58..4e83d1100d 100644 --- a/benchmarks/performance-poetry/complex-poetry/src/main/java/com/squareup/benchmarks/performance/complex/poetry/PerformancePoemsBrowserWorkflow.kt +++ b/benchmarks/performance-poetry/complex-poetry/src/main/java/com/squareup/benchmarks/performance/complex/poetry/PerformancePoemsBrowserWorkflow.kt @@ -21,6 +21,7 @@ import com.squareup.sample.poetry.PoemsBrowserWorkflow import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow import com.squareup.workflow1.WorkflowAction.Companion.noAction +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.runningWorker import com.squareup.workflow1.ui.WorkflowUiExperimentalApi @@ -70,7 +71,8 @@ class PerformancePoemsBrowserWorkflow( override fun initialState( props: ConfigAndPoems, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): State { return if (props.first.first > 0 && props.first.second == simulatedPerfConfig.recursionGraph.second diff --git a/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocompose/HelloWorkflow.kt b/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocompose/HelloWorkflow.kt index 16bc8142b9..1f623077a0 100644 --- a/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocompose/HelloWorkflow.kt +++ b/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocompose/HelloWorkflow.kt @@ -6,6 +6,7 @@ import com.squareup.sample.compose.hellocompose.HelloWorkflow.State.Goodbye import com.squareup.sample.compose.hellocompose.HelloWorkflow.State.Hello import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.parse import com.squareup.workflow1.ui.Screen @@ -34,7 +35,8 @@ object HelloWorkflow : StatefulWorkflow() { override fun initialState( props: Unit, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): State = snapshot?.bytes?.parse { source -> if (source.readInt() == 1) Hello else Goodbye } ?: Hello diff --git a/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposebinding/HelloWorkflow.kt b/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposebinding/HelloWorkflow.kt index 55555899e4..821967d893 100644 --- a/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposebinding/HelloWorkflow.kt +++ b/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposebinding/HelloWorkflow.kt @@ -6,6 +6,7 @@ import com.squareup.sample.compose.hellocomposebinding.HelloWorkflow.State.Goodb import com.squareup.sample.compose.hellocomposebinding.HelloWorkflow.State.Hello import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.parse import com.squareup.workflow1.ui.Screen @@ -34,7 +35,8 @@ object HelloWorkflow : StatefulWorkflow() { override fun initialState( props: Unit, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): State = snapshot?.bytes?.parse { source -> if (source.readInt() == 1) Hello else Goodbye } ?: Hello diff --git a/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposeworkflow/ComposeWorkflowImpl.kt b/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposeworkflow/ComposeWorkflowImpl.kt index 3a649575c9..1db683a554 100644 --- a/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposeworkflow/ComposeWorkflowImpl.kt +++ b/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposeworkflow/ComposeWorkflowImpl.kt @@ -8,6 +8,7 @@ import com.squareup.sample.compose.hellocomposeworkflow.ComposeWorkflowImpl.Stat import com.squareup.workflow1.Sink import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.contraMap import com.squareup.workflow1.ui.ViewEnvironment @@ -30,7 +31,8 @@ internal class ComposeWorkflowImpl( override fun initialState( props: PropsT, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): State { val propsHolder = mutableStateOf(props, policy = structuralEqualityPolicy()) val sinkHolder = SinkHolder() diff --git a/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposeworkflow/HelloWorkflow.kt b/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposeworkflow/HelloWorkflow.kt index 74560385f6..75de36cfea 100644 --- a/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposeworkflow/HelloWorkflow.kt +++ b/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposeworkflow/HelloWorkflow.kt @@ -5,6 +5,7 @@ import com.squareup.sample.compose.hellocomposeworkflow.HelloWorkflow.State.Good import com.squareup.sample.compose.hellocomposeworkflow.HelloWorkflow.State.Hello import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.parse import com.squareup.workflow1.ui.WorkflowUiExperimentalApi @@ -32,7 +33,8 @@ object HelloWorkflow : StatefulWorkflow() { override fun initialState( props: Unit, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): State = snapshot?.bytes?.parse { source -> if (source.readInt() == 1) Hello else Goodbye } ?: Hello diff --git a/samples/compose-samples/src/main/java/com/squareup/sample/compose/inlinerendering/InlineRenderingWorkflow.kt b/samples/compose-samples/src/main/java/com/squareup/sample/compose/inlinerendering/InlineRenderingWorkflow.kt index 8e53b70265..8c77d9fb0a 100644 --- a/samples/compose-samples/src/main/java/com/squareup/sample/compose/inlinerendering/InlineRenderingWorkflow.kt +++ b/samples/compose-samples/src/main/java/com/squareup/sample/compose/inlinerendering/InlineRenderingWorkflow.kt @@ -19,6 +19,7 @@ import androidx.compose.ui.tooling.preview.Preview import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow import com.squareup.workflow1.WorkflowExperimentalRuntime +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.config.AndroidRuntimeConfigTools import com.squareup.workflow1.parse import com.squareup.workflow1.ui.AndroidScreen @@ -32,7 +33,8 @@ object InlineRenderingWorkflow : StatefulWorkflow() { override fun initialState( props: Unit, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): State = State() override fun render( diff --git a/samples/compose-samples/src/main/java/com/squareup/sample/compose/textinput/TextInputWorkflow.kt b/samples/compose-samples/src/main/java/com/squareup/sample/compose/textinput/TextInputWorkflow.kt index f3772c2bdb..391675133e 100644 --- a/samples/compose-samples/src/main/java/com/squareup/sample/compose/textinput/TextInputWorkflow.kt +++ b/samples/compose-samples/src/main/java/com/squareup/sample/compose/textinput/TextInputWorkflow.kt @@ -4,6 +4,7 @@ import com.squareup.sample.compose.textinput.TextInputWorkflow.Rendering import com.squareup.sample.compose.textinput.TextInputWorkflow.State import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.ui.Screen import com.squareup.workflow1.ui.TextController @@ -29,7 +30,8 @@ object TextInputWorkflow : StatefulWorkflow() { override fun initialState( props: Unit, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): State = State() override fun render( diff --git a/samples/containers/hello-back-button/src/main/java/com/squareup/sample/hellobackbutton/AreYouSureWorkflow.kt b/samples/containers/hello-back-button/src/main/java/com/squareup/sample/hellobackbutton/AreYouSureWorkflow.kt index c18c08c9c6..616e330a70 100644 --- a/samples/containers/hello-back-button/src/main/java/com/squareup/sample/hellobackbutton/AreYouSureWorkflow.kt +++ b/samples/containers/hello-back-button/src/main/java/com/squareup/sample/hellobackbutton/AreYouSureWorkflow.kt @@ -9,6 +9,7 @@ import com.squareup.sample.hellobackbutton.AreYouSureWorkflow.State.Running import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow import com.squareup.workflow1.WorkflowAction.Companion.noAction +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.ui.AndroidScreen import com.squareup.workflow1.ui.Screen @@ -35,7 +36,8 @@ object AreYouSureWorkflow : StatefulWorkflow() { override fun initialState( props: Unit, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): State = snapshot?.toParcelable() ?: Running class Rendering( diff --git a/samples/containers/hello-back-button/src/main/java/com/squareup/sample/hellobackbutton/HelloBackButtonWorkflow.kt b/samples/containers/hello-back-button/src/main/java/com/squareup/sample/hellobackbutton/HelloBackButtonWorkflow.kt index 72cd4a3022..59fc838734 100644 --- a/samples/containers/hello-back-button/src/main/java/com/squareup/sample/hellobackbutton/HelloBackButtonWorkflow.kt +++ b/samples/containers/hello-back-button/src/main/java/com/squareup/sample/hellobackbutton/HelloBackButtonWorkflow.kt @@ -7,6 +7,7 @@ import com.squareup.sample.hellobackbutton.HelloBackButtonWorkflow.State.Baker import com.squareup.sample.hellobackbutton.HelloBackButtonWorkflow.State.Charlie import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.ui.toParcelable import com.squareup.workflow1.ui.toSnapshot import kotlinx.parcelize.Parcelize @@ -22,7 +23,8 @@ object HelloBackButtonWorkflow : StatefulWorkflow source.readInt() diff --git a/samples/containers/poetry/src/main/java/com/squareup/sample/poetry/RealPoemsBrowserWorkflow.kt b/samples/containers/poetry/src/main/java/com/squareup/sample/poetry/RealPoemsBrowserWorkflow.kt index 23ec363368..bfca321fd7 100644 --- a/samples/containers/poetry/src/main/java/com/squareup/sample/poetry/RealPoemsBrowserWorkflow.kt +++ b/samples/containers/poetry/src/main/java/com/squareup/sample/poetry/RealPoemsBrowserWorkflow.kt @@ -6,6 +6,7 @@ import com.squareup.sample.poetry.PoemListWorkflow.Props import com.squareup.sample.poetry.model.Poem import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.parse import com.squareup.workflow1.ui.WorkflowUiExperimentalApi @@ -27,7 +28,8 @@ class RealPoemsBrowserWorkflow( override fun initialState( props: ConfigAndPoems, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): SelectedPoem { return snapshot?.bytes?.parse { source -> source.readInt() diff --git a/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/DungeonAppWorkflow.kt b/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/DungeonAppWorkflow.kt index 80bb993c25..73e14553b4 100644 --- a/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/DungeonAppWorkflow.kt +++ b/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/DungeonAppWorkflow.kt @@ -10,6 +10,7 @@ import com.squareup.sample.dungeon.DungeonAppWorkflow.State.PlayingGame import com.squareup.sample.dungeon.board.Board import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.renderChild import com.squareup.workflow1.runningWorker @@ -38,7 +39,8 @@ class DungeonAppWorkflow( override fun initialState( props: Props, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): State = LoadingBoardList override fun render( diff --git a/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/GameSessionWorkflow.kt b/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/GameSessionWorkflow.kt index 270b964d71..211e2f8282 100644 --- a/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/GameSessionWorkflow.kt +++ b/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/GameSessionWorkflow.kt @@ -15,6 +15,7 @@ import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow import com.squareup.workflow1.WorkflowAction import com.squareup.workflow1.WorkflowAction.Companion.noAction +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.runningWorker import com.squareup.workflow1.ui.Screen @@ -48,7 +49,8 @@ class GameSessionWorkflow( override fun initialState( props: Props, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): State = Loading override fun render( diff --git a/samples/dungeon/common/src/main/java/com/squareup/sample/dungeon/AiWorkflow.kt b/samples/dungeon/common/src/main/java/com/squareup/sample/dungeon/AiWorkflow.kt index 3a6f64126f..2761191454 100644 --- a/samples/dungeon/common/src/main/java/com/squareup/sample/dungeon/AiWorkflow.kt +++ b/samples/dungeon/common/src/main/java/com/squareup/sample/dungeon/AiWorkflow.kt @@ -11,6 +11,7 @@ import com.squareup.sample.dungeon.board.BoardCell import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow import com.squareup.workflow1.Worker +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.runningWorker import com.squareup.workflow1.transform @@ -35,7 +36,8 @@ class AiWorkflow( override fun initialState( props: ActorProps, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): State { val startingDirection = random.nextEnum(Direction::class) return State(startingDirection, props.ticks.createDirectionTicker(random)) diff --git a/samples/dungeon/common/src/main/java/com/squareup/sample/dungeon/GameWorkflow.kt b/samples/dungeon/common/src/main/java/com/squareup/sample/dungeon/GameWorkflow.kt index 0024935fa6..1b41869c20 100644 --- a/samples/dungeon/common/src/main/java/com/squareup/sample/dungeon/GameWorkflow.kt +++ b/samples/dungeon/common/src/main/java/com/squareup/sample/dungeon/GameWorkflow.kt @@ -18,6 +18,7 @@ import com.squareup.sample.dungeon.board.Board.Location import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow import com.squareup.workflow1.Worker +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.renderChild import com.squareup.workflow1.runningWorker @@ -72,7 +73,8 @@ class GameWorkflow( override fun initialState( props: Props, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): State { val board = props.board return State( diff --git a/samples/dungeon/common/src/main/java/com/squareup/sample/dungeon/PlayerWorkflow.kt b/samples/dungeon/common/src/main/java/com/squareup/sample/dungeon/PlayerWorkflow.kt index fa5a5b9481..8e00c710d6 100644 --- a/samples/dungeon/common/src/main/java/com/squareup/sample/dungeon/PlayerWorkflow.kt +++ b/samples/dungeon/common/src/main/java/com/squareup/sample/dungeon/PlayerWorkflow.kt @@ -9,6 +9,7 @@ import com.squareup.sample.dungeon.board.BoardCell import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow import com.squareup.workflow1.WorkflowAction +import com.squareup.workflow1.WorkflowLocal /** * Workflow that represents the actual player of the game in the [GameWorkflow]. @@ -41,7 +42,8 @@ class PlayerWorkflow( override fun initialState( props: ActorProps, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): Movement = Movement(cellsPerSecond = cellsPerSecond) override fun render( diff --git a/samples/dungeon/timemachine-shakeable/src/main/java/com/squareup/sample/timemachine/shakeable/ShakeableTimeMachineWorkflow.kt b/samples/dungeon/timemachine-shakeable/src/main/java/com/squareup/sample/timemachine/shakeable/ShakeableTimeMachineWorkflow.kt index d6b1ad7b43..950d2880ce 100644 --- a/samples/dungeon/timemachine-shakeable/src/main/java/com/squareup/sample/timemachine/shakeable/ShakeableTimeMachineWorkflow.kt +++ b/samples/dungeon/timemachine-shakeable/src/main/java/com/squareup/sample/timemachine/shakeable/ShakeableTimeMachineWorkflow.kt @@ -10,6 +10,7 @@ import com.squareup.sample.timemachine.shakeable.ShakeableTimeMachineWorkflow.St import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow import com.squareup.workflow1.WorkflowAction +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.runningWorker import com.squareup.workflow1.ui.Screen @@ -48,7 +49,8 @@ class ShakeableTimeMachineWorkflow( override fun initialState( props: PropsFactory

, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): State = Recording override fun snapshotState(state: State): Snapshot? = null diff --git a/samples/dungeon/timemachine/src/main/java/com/squareup/sample/timemachine/RecorderWorkflow.kt b/samples/dungeon/timemachine/src/main/java/com/squareup/sample/timemachine/RecorderWorkflow.kt index 90e636c12f..a609597d9e 100644 --- a/samples/dungeon/timemachine/src/main/java/com/squareup/sample/timemachine/RecorderWorkflow.kt +++ b/samples/dungeon/timemachine/src/main/java/com/squareup/sample/timemachine/RecorderWorkflow.kt @@ -6,6 +6,7 @@ import com.squareup.sample.timemachine.RecorderWorkflow.RecorderProps.RecordValu import com.squareup.sample.timemachine.RecorderWorkflow.Recording import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow +import com.squareup.workflow1.WorkflowLocal import kotlin.time.Duration import kotlin.time.ExperimentalTime import kotlin.time.TimeMark @@ -49,7 +50,8 @@ internal class RecorderWorkflow( override fun initialState( props: RecorderProps, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): Recording { val now = clock.markNow() return Recording( diff --git a/samples/hello-terminal/hello-terminal-app/src/main/java/com/squareup/sample/helloterminal/BlinkingCursorWorkflow.kt b/samples/hello-terminal/hello-terminal-app/src/main/java/com/squareup/sample/helloterminal/BlinkingCursorWorkflow.kt index 8dad472f9a..e6890457f3 100644 --- a/samples/hello-terminal/hello-terminal-app/src/main/java/com/squareup/sample/helloterminal/BlinkingCursorWorkflow.kt +++ b/samples/hello-terminal/hello-terminal-app/src/main/java/com/squareup/sample/helloterminal/BlinkingCursorWorkflow.kt @@ -3,6 +3,7 @@ package com.squareup.sample.helloterminal import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow import com.squareup.workflow1.Worker +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.runningWorker import kotlinx.coroutines.delay @@ -29,7 +30,8 @@ class BlinkingCursorWorkflow( override fun initialState( props: Unit, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): Boolean = true override fun render( diff --git a/samples/hello-terminal/hello-terminal-app/src/main/java/com/squareup/sample/helloterminal/HelloTerminalWorkflow.kt b/samples/hello-terminal/hello-terminal-app/src/main/java/com/squareup/sample/helloterminal/HelloTerminalWorkflow.kt index a5a3926719..e25a5fe18a 100644 --- a/samples/hello-terminal/hello-terminal-app/src/main/java/com/squareup/sample/helloterminal/HelloTerminalWorkflow.kt +++ b/samples/hello-terminal/hello-terminal-app/src/main/java/com/squareup/sample/helloterminal/HelloTerminalWorkflow.kt @@ -11,6 +11,7 @@ import com.squareup.sample.helloterminal.terminalworkflow.TerminalWorkflow import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow import com.squareup.workflow1.WorkflowAction +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.renderChild import com.squareup.workflow1.runningWorker @@ -31,7 +32,8 @@ class HelloTerminalWorkflow : TerminalWorkflow, override fun initialState( props: TerminalProps, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ) = State() override fun render( diff --git a/samples/hello-terminal/todo-terminal-app/src/main/java/com/squareup/sample/hellotodo/EditTextWorkflow.kt b/samples/hello-terminal/todo-terminal-app/src/main/java/com/squareup/sample/hellotodo/EditTextWorkflow.kt index bdbbfbe11f..7d2b89c215 100644 --- a/samples/hello-terminal/todo-terminal-app/src/main/java/com/squareup/sample/hellotodo/EditTextWorkflow.kt +++ b/samples/hello-terminal/todo-terminal-app/src/main/java/com/squareup/sample/hellotodo/EditTextWorkflow.kt @@ -10,6 +10,7 @@ import com.squareup.sample.hellotodo.EditTextWorkflow.EditTextProps import com.squareup.sample.hellotodo.EditTextWorkflow.EditTextState import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.runningWorker @@ -30,7 +31,8 @@ class EditTextWorkflow : StatefulWorkflow() override fun initialState( props: Unit, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): State = snapshot?.bytes?.parse { source -> if (source.readInt() == 1) Hello else Goodbye } ?: Hello diff --git a/samples/hello-workflow/src/main/java/com/squareup/sample/helloworkflow/HelloWorkflow.kt b/samples/hello-workflow/src/main/java/com/squareup/sample/helloworkflow/HelloWorkflow.kt index b246a07e7b..584f690606 100644 --- a/samples/hello-workflow/src/main/java/com/squareup/sample/helloworkflow/HelloWorkflow.kt +++ b/samples/hello-workflow/src/main/java/com/squareup/sample/helloworkflow/HelloWorkflow.kt @@ -5,6 +5,7 @@ import com.squareup.sample.helloworkflow.HelloWorkflow.State.Goodbye import com.squareup.sample.helloworkflow.HelloWorkflow.State.Hello import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.parse @@ -16,7 +17,8 @@ object HelloWorkflow : StatefulWorkflow() override fun initialState( props: Unit, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): State = snapshot?.bytes?.parse { source -> if (source.readInt() == 1) Hello else Goodbye } ?: Hello diff --git a/samples/nested-overlays/src/main/java/com/squareup/sample/nestedoverlays/NestedOverlaysWorkflow.kt b/samples/nested-overlays/src/main/java/com/squareup/sample/nestedoverlays/NestedOverlaysWorkflow.kt index b694ed9f66..f5ffaabb36 100644 --- a/samples/nested-overlays/src/main/java/com/squareup/sample/nestedoverlays/NestedOverlaysWorkflow.kt +++ b/samples/nested-overlays/src/main/java/com/squareup/sample/nestedoverlays/NestedOverlaysWorkflow.kt @@ -5,6 +5,7 @@ package com.squareup.sample.nestedoverlays import com.squareup.sample.nestedoverlays.NestedOverlaysWorkflow.State import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.ui.Screen import com.squareup.workflow1.ui.WorkflowUiExperimentalApi import com.squareup.workflow1.ui.container.BackButtonScreen @@ -23,7 +24,8 @@ object NestedOverlaysWorkflow : StatefulWorkflow() override fun initialState( props: Unit, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ) = State() override fun render( diff --git a/samples/stub-visibility/src/main/java/com/squareup/sample/stubvisibility/StubVisibilityWorkflow.kt b/samples/stub-visibility/src/main/java/com/squareup/sample/stubvisibility/StubVisibilityWorkflow.kt index 77b6d5f4f3..901c2b916d 100644 --- a/samples/stub-visibility/src/main/java/com/squareup/sample/stubvisibility/StubVisibilityWorkflow.kt +++ b/samples/stub-visibility/src/main/java/com/squareup/sample/stubvisibility/StubVisibilityWorkflow.kt @@ -5,6 +5,7 @@ import com.squareup.sample.stubvisibility.StubVisibilityWorkflow.State.HideBotto import com.squareup.sample.stubvisibility.StubVisibilityWorkflow.State.ShowBottom import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.parse @@ -16,7 +17,8 @@ object StubVisibilityWorkflow : StatefulWorkflow if (source.readInt() == 1) HideBottom else ShowBottom } diff --git a/samples/tictactoe/common/src/main/java/com/squareup/sample/authworkflow/AuthWorkflow.kt b/samples/tictactoe/common/src/main/java/com/squareup/sample/authworkflow/AuthWorkflow.kt index 9ae4f3738e..d6914ee323 100644 --- a/samples/tictactoe/common/src/main/java/com/squareup/sample/authworkflow/AuthWorkflow.kt +++ b/samples/tictactoe/common/src/main/java/com/squareup/sample/authworkflow/AuthWorkflow.kt @@ -12,6 +12,7 @@ import com.squareup.sample.authworkflow.AuthState.SecondFactorPrompt import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow import com.squareup.workflow1.Workflow +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.runningWorker import com.squareup.workflow1.rx2.asWorker @@ -66,7 +67,8 @@ class RealAuthWorkflow(private val authService: AuthService) : AuthWorkflow, override fun initialState( props: Unit, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): AuthState = LoginPrompt() override fun render( diff --git a/samples/tictactoe/common/src/main/java/com/squareup/sample/gameworkflow/RunGameWorkflow.kt b/samples/tictactoe/common/src/main/java/com/squareup/sample/gameworkflow/RunGameWorkflow.kt index 5d65ef66e6..ea5fe8e5c3 100644 --- a/samples/tictactoe/common/src/main/java/com/squareup/sample/gameworkflow/RunGameWorkflow.kt +++ b/samples/tictactoe/common/src/main/java/com/squareup/sample/gameworkflow/RunGameWorkflow.kt @@ -18,6 +18,7 @@ import com.squareup.sample.gameworkflow.SyncState.SAVING import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow import com.squareup.workflow1.Workflow +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.runningWorker import com.squareup.workflow1.rx2.asWorker @@ -68,7 +69,8 @@ class RealRunGameWorkflow( override fun initialState( props: Unit, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): RunGameState { return snapshot?.let { RunGameState.fromSnapshot(snapshot.bytes) } ?: NewGame() diff --git a/samples/tictactoe/common/src/main/java/com/squareup/sample/gameworkflow/TakeTurnsWorkflow.kt b/samples/tictactoe/common/src/main/java/com/squareup/sample/gameworkflow/TakeTurnsWorkflow.kt index 10b086a9ba..1be5bc34eb 100644 --- a/samples/tictactoe/common/src/main/java/com/squareup/sample/gameworkflow/TakeTurnsWorkflow.kt +++ b/samples/tictactoe/common/src/main/java/com/squareup/sample/gameworkflow/TakeTurnsWorkflow.kt @@ -9,6 +9,7 @@ import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow import com.squareup.workflow1.Workflow import com.squareup.workflow1.WorkflowAction +import com.squareup.workflow1.WorkflowLocal typealias TakeTurnsWorkflow = Workflow @@ -63,7 +64,8 @@ class RealTakeTurnsWorkflow : TakeTurnsWorkflow, override fun initialState( props: TakeTurnsProps, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): Turn = props.initialTurn override fun render( diff --git a/samples/tictactoe/common/src/main/java/com/squareup/sample/mainworkflow/TicTacToeWorkflow.kt b/samples/tictactoe/common/src/main/java/com/squareup/sample/mainworkflow/TicTacToeWorkflow.kt index 927b1103b5..e6e2bfb584 100644 --- a/samples/tictactoe/common/src/main/java/com/squareup/sample/mainworkflow/TicTacToeWorkflow.kt +++ b/samples/tictactoe/common/src/main/java/com/squareup/sample/mainworkflow/TicTacToeWorkflow.kt @@ -16,6 +16,7 @@ import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow import com.squareup.workflow1.Workflow import com.squareup.workflow1.WorkflowAction.Companion.noAction +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.renderChild import com.squareup.workflow1.ui.WorkflowUiExperimentalApi @@ -48,7 +49,8 @@ class TicTacToeWorkflow( override fun initialState( props: Unit, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): MainState = snapshot?.let { MainState.fromSnapshot(snapshot.bytes) } ?: Authenticating diff --git a/samples/todo-android/app/src/main/java/com/squareup/sample/todo/TodoEditorWorkflow.kt b/samples/todo-android/app/src/main/java/com/squareup/sample/todo/TodoEditorWorkflow.kt index 4584c4cf8a..9af8288450 100644 --- a/samples/todo-android/app/src/main/java/com/squareup/sample/todo/TodoEditorWorkflow.kt +++ b/samples/todo-android/app/src/main/java/com/squareup/sample/todo/TodoEditorWorkflow.kt @@ -7,6 +7,7 @@ import com.squareup.sample.todo.TodoEditorOutput.Done import com.squareup.sample.todo.TodoEditorOutput.ListUpdated import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.asWorker import com.squareup.workflow1.runningWorker @@ -31,7 +32,8 @@ class TodoEditorWorkflow : StatefulWorkflow() { override fun initialState( props: TodoList, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): TodoEditingSession = props.toEditingSession() override fun snapshotState(state: TodoEditingSession): Snapshot? = null diff --git a/samples/todo-android/app/src/main/java/com/squareup/sample/todo/TodoListsAppWorkflow.kt b/samples/todo-android/app/src/main/java/com/squareup/sample/todo/TodoListsAppWorkflow.kt index d49b9ad092..c4116df793 100644 --- a/samples/todo-android/app/src/main/java/com/squareup/sample/todo/TodoListsAppWorkflow.kt +++ b/samples/todo-android/app/src/main/java/com/squareup/sample/todo/TodoListsAppWorkflow.kt @@ -8,6 +8,7 @@ import com.squareup.sample.todo.TodoListsAppState.ShowingLists import com.squareup.sample.todo.TodoListsAppWorkflow.render import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.ui.WorkflowUiExperimentalApi import com.squareup.workflow1.ui.container.BackStackScreen @@ -31,7 +32,8 @@ object TodoListsAppWorkflow : StatefulWorkflow() { override fun initialState( props: Unit, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): TodoListsAppState = ShowingLists( listOf( TodoList("Groceries"), diff --git a/workflow-core/api/workflow-core.api b/workflow-core/api/workflow-core.api index ce84a00002..f0bc8b8d38 100644 --- a/workflow-core/api/workflow-core.api +++ b/workflow-core/api/workflow-core.api @@ -35,6 +35,7 @@ public abstract interface class com/squareup/workflow1/BaseRenderContext { public abstract fun eventHandler (Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function8;)Lkotlin/jvm/functions/Function7; public abstract fun eventHandler (Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function9;)Lkotlin/jvm/functions/Function8; public abstract fun getActionSink ()Lcom/squareup/workflow1/Sink; + public abstract fun getWorkflowLocal ()Lcom/squareup/workflow1/LocalMap; public abstract fun renderChild (Lcom/squareup/workflow1/Workflow;Ljava/lang/Object;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public abstract fun runningSideEffect (Ljava/lang/String;Lkotlin/jvm/functions/Function2;)V } @@ -62,6 +63,7 @@ public final class com/squareup/workflow1/BaseRenderContext$DefaultImpls { public static synthetic fun eventHandler$default (Lcom/squareup/workflow1/BaseRenderContext;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function7;ILjava/lang/Object;)Lkotlin/jvm/functions/Function6; public static synthetic fun eventHandler$default (Lcom/squareup/workflow1/BaseRenderContext;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function8;ILjava/lang/Object;)Lkotlin/jvm/functions/Function7; public static synthetic fun eventHandler$default (Lcom/squareup/workflow1/BaseRenderContext;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function9;ILjava/lang/Object;)Lkotlin/jvm/functions/Function8; + public static fun getWorkflowLocal (Lcom/squareup/workflow1/BaseRenderContext;)Lcom/squareup/workflow1/LocalMap; public static synthetic fun renderChild$default (Lcom/squareup/workflow1/BaseRenderContext;Lcom/squareup/workflow1/Workflow;Ljava/lang/Object;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/Object; } @@ -87,6 +89,33 @@ public abstract class com/squareup/workflow1/LifecycleWorker : com/squareup/work public final fun run ()Lkotlinx/coroutines/flow/Flow; } +public class com/squareup/workflow1/LocalMap { + public static final field Companion Lcom/squareup/workflow1/LocalMap$Companion; + public fun ()V + public fun (Ljava/util/Map;)V + public synthetic fun (Ljava/util/Map;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun equals (Ljava/lang/Object;)Z + public final fun get (Lcom/squareup/workflow1/LocalMapKey;)Ljava/lang/Object; + public final fun getMap ()Ljava/util/Map; + public fun hashCode ()I + public final fun plus (Lcom/squareup/workflow1/LocalMap;)Lcom/squareup/workflow1/LocalMap; + public final fun plus (Lkotlin/Pair;)Lcom/squareup/workflow1/LocalMap; + public fun toString ()Ljava/lang/String; +} + +public final class com/squareup/workflow1/LocalMap$Companion { + public final fun getEMPTY ()Lcom/squareup/workflow1/LocalMap; +} + +public abstract class com/squareup/workflow1/LocalMapKey { + public fun ()V + public fun (Lkotlin/reflect/KClass;)V + public fun combine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public final fun equals (Ljava/lang/Object;)Z + public abstract fun getDefault ()Ljava/lang/Object; + public final fun hashCode ()I +} + public final class com/squareup/workflow1/PropsUpdated : com/squareup/workflow1/ActionProcessingResult { public static final field INSTANCE Lcom/squareup/workflow1/PropsUpdated; } @@ -141,7 +170,8 @@ public abstract class com/squareup/workflow1/StatefulWorkflow : com/squareup/wor public fun ()V public final fun asStatefulWorkflow ()Lcom/squareup/workflow1/StatefulWorkflow; public fun getCachedIdentifier ()Lcom/squareup/workflow1/WorkflowIdentifier; - public abstract fun initialState (Ljava/lang/Object;Lcom/squareup/workflow1/Snapshot;)Ljava/lang/Object; + public abstract fun initialState (Ljava/lang/Object;Lcom/squareup/workflow1/Snapshot;Lcom/squareup/workflow1/LocalMap;)Ljava/lang/Object; + public fun nodeCreated (Lkotlinx/coroutines/CoroutineScope;Lcom/squareup/workflow1/LocalMap;)Lcom/squareup/workflow1/LocalMap; public fun onPropsChanged (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun render (Ljava/lang/Object;Ljava/lang/Object;Lcom/squareup/workflow1/StatefulWorkflow$RenderContext;)Ljava/lang/Object; public fun setCachedIdentifier (Lcom/squareup/workflow1/WorkflowIdentifier;)V @@ -161,6 +191,7 @@ public final class com/squareup/workflow1/StatefulWorkflow$RenderContext : com/s public fun eventHandler (Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function8;)Lkotlin/jvm/functions/Function7; public fun eventHandler (Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function9;)Lkotlin/jvm/functions/Function8; public fun getActionSink ()Lcom/squareup/workflow1/Sink; + public fun getWorkflowLocal ()Lcom/squareup/workflow1/LocalMap; public fun renderChild (Lcom/squareup/workflow1/Workflow;Ljava/lang/Object;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun runningSideEffect (Ljava/lang/String;Lkotlin/jvm/functions/Function2;)V } @@ -186,6 +217,7 @@ public final class com/squareup/workflow1/StatelessWorkflow$RenderContext : com/ public fun eventHandler (Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function8;)Lkotlin/jvm/functions/Function7; public fun eventHandler (Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function9;)Lkotlin/jvm/functions/Function8; public fun getActionSink ()Lcom/squareup/workflow1/Sink; + public fun getWorkflowLocal ()Lcom/squareup/workflow1/LocalMap; public fun renderChild (Lcom/squareup/workflow1/Workflow;Ljava/lang/Object;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun runningSideEffect (Ljava/lang/String;Lkotlin/jvm/functions/Function2;)V } @@ -288,6 +320,10 @@ public final class com/squareup/workflow1/WorkflowIdentifierType$Unsnapshottable public fun toString ()Ljava/lang/String; } +public final class com/squareup/workflow1/WorkflowLocalKt { + public static final fun getEmptyWorkflowLocal ()Lcom/squareup/workflow1/LocalMap; +} + public final class com/squareup/workflow1/WorkflowOutput { public fun (Ljava/lang/Object;)V public fun equals (Ljava/lang/Object;)Z @@ -325,9 +361,11 @@ public final class com/squareup/workflow1/Workflows { public static final fun stateful (Lcom/squareup/workflow1/Workflow$Companion;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Lcom/squareup/workflow1/StatefulWorkflow; public static final fun stateful (Lcom/squareup/workflow1/Workflow$Companion;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)Lcom/squareup/workflow1/StatefulWorkflow; public static final fun stateful (Lcom/squareup/workflow1/Workflow$Companion;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;)Lcom/squareup/workflow1/StatefulWorkflow; - public static final fun stateful (Lcom/squareup/workflow1/Workflow$Companion;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;)Lcom/squareup/workflow1/StatefulWorkflow; + public static final fun stateful (Lcom/squareup/workflow1/Workflow$Companion;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;)Lcom/squareup/workflow1/StatefulWorkflow; + public static final fun stateful (Lcom/squareup/workflow1/Workflow$Companion;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;)Lcom/squareup/workflow1/StatefulWorkflow; public static synthetic fun stateful$default (Lcom/squareup/workflow1/Workflow$Companion;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;ILjava/lang/Object;)Lcom/squareup/workflow1/StatefulWorkflow; - public static synthetic fun stateful$default (Lcom/squareup/workflow1/Workflow$Companion;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;ILjava/lang/Object;)Lcom/squareup/workflow1/StatefulWorkflow; + public static synthetic fun stateful$default (Lcom/squareup/workflow1/Workflow$Companion;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;ILjava/lang/Object;)Lcom/squareup/workflow1/StatefulWorkflow; + public static synthetic fun stateful$default (Lcom/squareup/workflow1/Workflow$Companion;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;ILjava/lang/Object;)Lcom/squareup/workflow1/StatefulWorkflow; public static final fun stateless (Lcom/squareup/workflow1/Workflow$Companion;Lkotlin/jvm/functions/Function2;)Lcom/squareup/workflow1/Workflow; public static final fun transform (Lcom/squareup/workflow1/Worker;Lkotlin/jvm/functions/Function1;)Lcom/squareup/workflow1/Worker; public static final fun unsnapshottableIdentifier (Lkotlin/reflect/KType;)Lcom/squareup/workflow1/WorkflowIdentifier; diff --git a/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/BaseRenderContext.kt b/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/BaseRenderContext.kt index e28dabdada..a2bb475f4a 100644 --- a/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/BaseRenderContext.kt +++ b/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/BaseRenderContext.kt @@ -45,6 +45,16 @@ import kotlin.reflect.typeOf */ public interface BaseRenderContext { + /** + * The [WorkflowLocal] for the Workflow session providing this render context. + * @see [WorkflowLocal] + * + * If a special [BaseRenderContext] is being used (for testing or otherwise) we just keep this + * empty by default. + */ + public val workflowLocal: WorkflowLocal + get() = EmptyWorkflowLocal + /** * Accepts a single [WorkflowAction], invokes that action by calling [WorkflowAction.apply] * to update the current state, and optionally emits the returned output value if it is non-null. diff --git a/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/LocalMap.kt b/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/LocalMap.kt new file mode 100644 index 0000000000..a510dc9057 --- /dev/null +++ b/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/LocalMap.kt @@ -0,0 +1,94 @@ +package com.squareup.workflow1 + +import kotlin.reflect.KClass + +/** + * Immutable map of values that a parent can pass down to + * its children. Allows containers to give descendants information about + * the context in which they're drawing. + * + */ +public open class LocalMap +@Deprecated( + "To eliminate runtime errors this constructor will become private. " + + "Use LocalMap.EMPTY and LocalMap.plus" +) +constructor( + public val map: Map, Any> = emptyMap() +) { + public operator fun get(key: LocalMapKey): T = getOrNull(key) ?: key.default + + public operator fun plus(pair: Pair, T>): LocalMap { + val (newKey, newValue) = pair + val newPair = getOrNull(newKey) + ?.let { oldValue -> newKey to newKey.combine(oldValue, newValue) } + ?: pair + @Suppress("DEPRECATION") + return LocalMap(map + newPair) + } + + public operator fun plus(other: LocalMap): LocalMap { + if (this == other) return this + if (other.map.isEmpty()) return this + if (map.isEmpty()) return other + val newMap = map.toMutableMap() + other.map.entries.forEach { (key, value) -> + @Suppress("UNCHECKED_CAST") + newMap[key] = getOrNull(key as LocalMapKey) + ?.let { oldValue -> key.combine(oldValue, value) } + ?: value + } + @Suppress("DEPRECATION") + return LocalMap(newMap) + } + + override fun toString(): String = "LocalMap($map)" + + override fun equals(other: Any?): Boolean = + (other as? LocalMap)?.let { it.map == map } ?: false + + override fun hashCode(): Int = map.hashCode() + + @Suppress("UNCHECKED_CAST") + private fun getOrNull(key: LocalMapKey): T? = map[key] as? T + + public companion object { + @Suppress("DEPRECATION") + public val EMPTY: LocalMap = LocalMap() + } +} + +/** + * Defines a value type [T] that can be provided by a [LocalMap] map, + * and specifies its [default] value. + * + * It is hard to imagine a useful implementation of this that is not a Kotlin `object`. + * Preferred use is to have the `companion object` of [T] extend this class. See + * [BackStackConfig.Companion][com.squareup.workflow1.ui.container.BackStackConfig.Companion] + * for an example. + */ +public abstract class LocalMapKey() { + @Deprecated("Use no args constructor", ReplaceWith("LocalMapKey()")) + public constructor(@Suppress("UNUSED_PARAMETER") type: KClass) : this() + + /** + * Defines the default value for this key. It is a grievous error for this value to be + * dynamic in any way. + */ + public abstract val default: T + + /** + * Applied from [LocalMap.plus] when the receiving environment already contains + * a value for this key. The default implementation replaces [left] with [right]. + */ + public open fun combine( + left: T, + right: T + ): T = right + + final override fun equals(other: Any?): Boolean { + return this === other || (other != null && this::class == other::class) + } + + final override fun hashCode(): Int = this::class.hashCode() +} diff --git a/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/StatefulWorkflow.kt b/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/StatefulWorkflow.kt index 829223b7c9..61794b131c 100644 --- a/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/StatefulWorkflow.kt +++ b/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/StatefulWorkflow.kt @@ -6,7 +6,7 @@ package com.squareup.workflow1 import com.squareup.workflow1.StatefulWorkflow.RenderContext import com.squareup.workflow1.WorkflowAction.Companion.toString -import kotlin.LazyThreadSafetyMode.NONE +import kotlinx.coroutines.CoroutineScope import kotlin.jvm.JvmMultifileClass import kotlin.jvm.JvmName @@ -76,6 +76,23 @@ public abstract class StatefulWorkflow< baseContext: BaseRenderContext ) : BaseRenderContext<@UnsafeVariance PropsT, StateT, @UnsafeVariance OutputT> by baseContext + /** + * Called when this Workflow's node (and [CoroutineScope]) is first created (when it is first + * rendered in the tree either from the root, or via [RenderContext.renderChild]). + * + * @param workflowNodeScope the [CoroutineScope] of the node in the Workflow tree that represents + * the lifetime of this Workflow. + * @param parentLocal the [WorkflowLocal] passed on by the parent of this Workflow. + * + * @return A [WorkflowLocal] map of non-state objects are needed by this Workflow and all its + * children. These are computed signals, such as a [StateFlow] whose needs correspond with the + * lifetime of this Workflow's node. I.e. the extent of [workflowNodeScope] + */ + public open fun nodeCreated( + workflowNodeScope: CoroutineScope, + parentLocal: WorkflowLocal + ): WorkflowLocal = parentLocal + /** * Called from [RenderContext.renderChild] when the state machine is first started, to get the * initial state. @@ -87,10 +104,14 @@ public abstract class StatefulWorkflow< * If the workflow is being restored from a [Snapshot], [snapshot] will be the last value * returned from [snapshotState], and implementations that return something other than * `null` should create their initial state by parsing their snapshot. + * + * @param workflowLocal - this is the [WorkflowLocal] map of non-state objects that have been + * added in [nodeCreated] or passed to this Workflow by its parent. */ public abstract fun initialState( props: PropsT, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): StateT /** @@ -176,23 +197,23 @@ public fun RenderContext( * Returns a stateful [Workflow] implemented via the given functions. */ public inline fun Workflow.Companion.stateful( - crossinline initialState: (PropsT, Snapshot?) -> StateT, - crossinline render: BaseRenderContext.( - props: PropsT, - state: StateT - ) -> RenderingT, + crossinline nodeCreated: (CoroutineScope, WorkflowLocal) -> WorkflowLocal, + crossinline initialState: (PropsT, Snapshot?, WorkflowLocal) -> StateT, + crossinline render: BaseRenderContext.(PropsT, StateT) -> RenderingT, crossinline snapshot: (StateT) -> Snapshot?, - crossinline onPropsChanged: ( - old: PropsT, - new: PropsT, - state: StateT - ) -> StateT = { _, _, state -> state } + crossinline onPropsChanged: (PropsT, PropsT, StateT) -> StateT = { _, _, state -> state } ): StatefulWorkflow = object : StatefulWorkflow() { + override fun nodeCreated( + workflowNodeScope: CoroutineScope, + parentLocal: WorkflowLocal + ): WorkflowLocal = nodeCreated(workflowNodeScope, parentLocal) + override fun initialState( props: PropsT, - snapshot: Snapshot? - ): StateT = initialState(props, snapshot) + snapshot: Snapshot?, + workflowLocal: WorkflowLocal + ): StateT = initialState(props, snapshot, workflowLocal) override fun onPropsChanged( old: PropsT, @@ -209,6 +230,22 @@ public inline fun Workflow.Companion.state override fun snapshotState(state: StateT) = snapshot(state) } +/** + * Returns a stateful [Workflow] implemented via the given functions. + */ +public inline fun Workflow.Companion.stateful( + crossinline initialState: (PropsT, Snapshot?, WorkflowLocal) -> StateT, + crossinline render: BaseRenderContext.(PropsT, StateT) -> RenderingT, + crossinline snapshot: (StateT) -> Snapshot?, + crossinline onPropsChanged: (PropsT, PropsT, StateT) -> StateT = { _, _, state -> state } +): StatefulWorkflow = stateful( + { _, parentLocal -> parentLocal }, + initialState, + render, + snapshot, + onPropsChanged +) + /** * Returns a stateful [Workflow], with no props, implemented via the given functions. */ @@ -217,7 +254,7 @@ public inline fun Workflow.Companion.stateful( crossinline render: BaseRenderContext.(state: StateT) -> RenderingT, crossinline snapshot: (StateT) -> Snapshot? ): StatefulWorkflow = stateful( - { _, initialSnapshot -> initialState(initialSnapshot) }, + { _, initialSnapshot, _ -> initialState(initialSnapshot) }, { _, state -> render(state) }, snapshot ) @@ -239,7 +276,7 @@ public inline fun Workflow.Companion.state state: StateT ) -> StateT = { _, _, state -> state } ): StatefulWorkflow = stateful( - { props, _ -> initialState(props) }, + { props, _, _ -> initialState(props) }, render, { null }, onPropsChanged diff --git a/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/WorkerWorkflow.kt b/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/WorkerWorkflow.kt index 983f7ac5de..df2baab12d 100644 --- a/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/WorkerWorkflow.kt +++ b/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/WorkerWorkflow.kt @@ -39,7 +39,8 @@ internal class WorkerWorkflow( override fun initialState( props: Worker, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): Int = 0 override fun onPropsChanged( diff --git a/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/WorkflowLocal.kt b/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/WorkflowLocal.kt new file mode 100644 index 0000000000..e55d0e3671 --- /dev/null +++ b/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/WorkflowLocal.kt @@ -0,0 +1,19 @@ +package com.squareup.workflow1 + +public typealias WorkflowLocalKey = LocalMapKey + +/** + * Immutable map of non-state values that a parent Workflow can pass down to + * its children. Allows Workflows to give descendants some signals that are established for the + * lifetime of the ancestor who added it. + * + * Why note use the Workflow's state? These are dependencies - or computations built off + * dependencies (such as a StateFlow tied to the Workflow node's CoroutineScope) - that are used + * by the Workflow over the course of its rendering, but that are not part of the 'state' of the + * Workflow, especially because they are likely hard to compare for equality. + * + * @see LocalMap for implementation + */ +public typealias WorkflowLocal = LocalMap + +public val EmptyWorkflowLocal: WorkflowLocal = LocalMap.Companion.EMPTY diff --git a/workflow-runtime/api/workflow-runtime.api b/workflow-runtime/api/workflow-runtime.api index f4d0c92b20..3a363fd5c7 100644 --- a/workflow-runtime/api/workflow-runtime.api +++ b/workflow-runtime/api/workflow-runtime.api @@ -1,10 +1,10 @@ public final class com/squareup/workflow1/NoopWorkflowInterceptor : com/squareup/workflow1/WorkflowInterceptor { public static final field INSTANCE Lcom/squareup/workflow1/NoopWorkflowInterceptor; - public fun onInitialState (Ljava/lang/Object;Lcom/squareup/workflow1/Snapshot;Lkotlin/jvm/functions/Function2;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object; + public fun onInitialState (Ljava/lang/Object;Lcom/squareup/workflow1/Snapshot;Lcom/squareup/workflow1/LocalMap;Lkotlin/jvm/functions/Function3;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object; + public fun onNodeCreated (Lkotlinx/coroutines/CoroutineScope;Lcom/squareup/workflow1/LocalMap;Lkotlin/jvm/functions/Function2;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Lcom/squareup/workflow1/LocalMap; public fun onPropsChanged (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function3;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object; public fun onRender (Ljava/lang/Object;Ljava/lang/Object;Lcom/squareup/workflow1/BaseRenderContext;Lkotlin/jvm/functions/Function3;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object; public fun onRenderAndSnapshot (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Lcom/squareup/workflow1/RenderingAndSnapshot; - public fun onSessionStarted (Lkotlinx/coroutines/CoroutineScope;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)V public fun onSnapshotState (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Lcom/squareup/workflow1/Snapshot; public fun onSnapshotStateWithChildren (Lkotlin/jvm/functions/Function0;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Lcom/squareup/workflow1/TreeSnapshot; } @@ -41,11 +41,11 @@ public class com/squareup/workflow1/SimpleLoggingWorkflowInterceptor : com/squar protected fun logAfterMethod (Ljava/lang/String;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;[Lkotlin/Pair;)V protected fun logBeforeMethod (Ljava/lang/String;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;[Lkotlin/Pair;)V protected fun logError (Ljava/lang/String;)V - public fun onInitialState (Ljava/lang/Object;Lcom/squareup/workflow1/Snapshot;Lkotlin/jvm/functions/Function2;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object; + public fun onInitialState (Ljava/lang/Object;Lcom/squareup/workflow1/Snapshot;Lcom/squareup/workflow1/LocalMap;Lkotlin/jvm/functions/Function3;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object; + public fun onNodeCreated (Lkotlinx/coroutines/CoroutineScope;Lcom/squareup/workflow1/LocalMap;Lkotlin/jvm/functions/Function2;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Lcom/squareup/workflow1/LocalMap; public fun onPropsChanged (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function3;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object; public fun onRender (Ljava/lang/Object;Ljava/lang/Object;Lcom/squareup/workflow1/BaseRenderContext;Lkotlin/jvm/functions/Function3;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object; public fun onRenderAndSnapshot (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Lcom/squareup/workflow1/RenderingAndSnapshot; - public fun onSessionStarted (Lkotlinx/coroutines/CoroutineScope;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)V public fun onSnapshotState (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Lcom/squareup/workflow1/Snapshot; public fun onSnapshotStateWithChildren (Lkotlin/jvm/functions/Function0;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Lcom/squareup/workflow1/TreeSnapshot; } @@ -66,21 +66,21 @@ public abstract interface annotation class com/squareup/workflow1/WorkflowExperi } public abstract interface class com/squareup/workflow1/WorkflowInterceptor { - public abstract fun onInitialState (Ljava/lang/Object;Lcom/squareup/workflow1/Snapshot;Lkotlin/jvm/functions/Function2;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object; + public abstract fun onInitialState (Ljava/lang/Object;Lcom/squareup/workflow1/Snapshot;Lcom/squareup/workflow1/LocalMap;Lkotlin/jvm/functions/Function3;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object; + public abstract fun onNodeCreated (Lkotlinx/coroutines/CoroutineScope;Lcom/squareup/workflow1/LocalMap;Lkotlin/jvm/functions/Function2;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Lcom/squareup/workflow1/LocalMap; public abstract fun onPropsChanged (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function3;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object; public abstract fun onRender (Ljava/lang/Object;Ljava/lang/Object;Lcom/squareup/workflow1/BaseRenderContext;Lkotlin/jvm/functions/Function3;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object; public abstract fun onRenderAndSnapshot (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Lcom/squareup/workflow1/RenderingAndSnapshot; - public abstract fun onSessionStarted (Lkotlinx/coroutines/CoroutineScope;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)V public abstract fun onSnapshotState (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Lcom/squareup/workflow1/Snapshot; public abstract fun onSnapshotStateWithChildren (Lkotlin/jvm/functions/Function0;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Lcom/squareup/workflow1/TreeSnapshot; } public final class com/squareup/workflow1/WorkflowInterceptor$DefaultImpls { - public static fun onInitialState (Lcom/squareup/workflow1/WorkflowInterceptor;Ljava/lang/Object;Lcom/squareup/workflow1/Snapshot;Lkotlin/jvm/functions/Function2;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object; + public static fun onInitialState (Lcom/squareup/workflow1/WorkflowInterceptor;Ljava/lang/Object;Lcom/squareup/workflow1/Snapshot;Lcom/squareup/workflow1/LocalMap;Lkotlin/jvm/functions/Function3;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object; + public static fun onNodeCreated (Lcom/squareup/workflow1/WorkflowInterceptor;Lkotlinx/coroutines/CoroutineScope;Lcom/squareup/workflow1/LocalMap;Lkotlin/jvm/functions/Function2;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Lcom/squareup/workflow1/LocalMap; public static fun onPropsChanged (Lcom/squareup/workflow1/WorkflowInterceptor;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function3;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object; public static fun onRender (Lcom/squareup/workflow1/WorkflowInterceptor;Ljava/lang/Object;Ljava/lang/Object;Lcom/squareup/workflow1/BaseRenderContext;Lkotlin/jvm/functions/Function3;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object; public static fun onRenderAndSnapshot (Lcom/squareup/workflow1/WorkflowInterceptor;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Lcom/squareup/workflow1/RenderingAndSnapshot; - public static fun onSessionStarted (Lcom/squareup/workflow1/WorkflowInterceptor;Lkotlinx/coroutines/CoroutineScope;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)V public static fun onSnapshotState (Lcom/squareup/workflow1/WorkflowInterceptor;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Lcom/squareup/workflow1/Snapshot; public static fun onSnapshotStateWithChildren (Lcom/squareup/workflow1/WorkflowInterceptor;Lkotlin/jvm/functions/Function0;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Lcom/squareup/workflow1/TreeSnapshot; } @@ -103,5 +103,10 @@ public abstract interface class com/squareup/workflow1/WorkflowInterceptor$Workf public abstract fun getRenderKey ()Ljava/lang/String; public abstract fun getRuntimeConfig ()Ljava/util/Set; public abstract fun getSessionId ()J + public abstract fun getWorkflowLocal ()Lcom/squareup/workflow1/LocalMap; +} + +public final class com/squareup/workflow1/WorkflowInterceptor$WorkflowSession$DefaultImpls { + public static fun getWorkflowLocal (Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Lcom/squareup/workflow1/LocalMap; } diff --git a/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/SimpleLoggingWorkflowInterceptor.kt b/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/SimpleLoggingWorkflowInterceptor.kt index 2b6e624338..b880e51deb 100644 --- a/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/SimpleLoggingWorkflowInterceptor.kt +++ b/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/SimpleLoggingWorkflowInterceptor.kt @@ -9,23 +9,27 @@ import kotlinx.coroutines.Job * A [WorkflowInterceptor] that just prints all method calls using [log]. */ public open class SimpleLoggingWorkflowInterceptor : WorkflowInterceptor { - override fun onSessionStarted( - workflowScope: CoroutineScope, + override fun onNodeCreated( + workflowNodeScope: CoroutineScope, + parentLocal: WorkflowLocal, + proceed: (CoroutineScope, WorkflowLocal) -> WorkflowLocal, session: WorkflowSession - ) { + ): WorkflowLocal { invokeSafely("logBeforeMethod") { logBeforeMethod("onInstanceStarted", session) } - workflowScope.coroutineContext[Job]!!.invokeOnCompletion { + workflowNodeScope.coroutineContext[Job]!!.invokeOnCompletion { invokeSafely("logAfterMethod") { logAfterMethod("onInstanceStarted", session) } } + return proceed(workflowNodeScope, parentLocal) } override fun onInitialState( props: P, snapshot: Snapshot?, - proceed: (P, Snapshot?) -> S, + workflowLocal: WorkflowLocal, + proceed: (P, Snapshot?, WorkflowLocal) -> S, session: WorkflowSession ): S = logMethod("onInitialState", session) { - proceed(props, snapshot) + proceed(props, snapshot, workflowLocal) } override fun onPropsChanged( diff --git a/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/WorkflowInterceptor.kt b/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/WorkflowInterceptor.kt index b8eb64039a..88a5215eee 100644 --- a/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/WorkflowInterceptor.kt +++ b/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/WorkflowInterceptor.kt @@ -12,7 +12,7 @@ import kotlin.coroutines.coroutineContext * of workflows. * * This interface's methods mirror the methods of [StatefulWorkflow]. It also has one additional - * method, [onSessionStarted], that is notified when a workflow is started. Each method returns the + * method, [onNodeCreated], that is notified when a workflow is started. Each method returns the * same thing as the corresponding method on [StatefulWorkflow], and receives the same parameters * as well as two extra parameters: * @@ -58,13 +58,15 @@ public interface WorkflowInterceptor { /** * Called when the session is starting, before [onInitialState]. * - * @param workflowScope The [CoroutineScope] that will be used for any side effects the workflow - * runs, as well as the parent for any workflows it renders. + * @param workflowNodeScope The [CoroutineScope] that will be used for any side effects the + * workflow runs, as well as the parent for any workflows it renders. */ - public fun onSessionStarted( - workflowScope: CoroutineScope, + public fun onNodeCreated( + workflowNodeScope: CoroutineScope, + parentLocal: WorkflowLocal, + proceed: (CoroutineScope, WorkflowLocal) -> WorkflowLocal, session: WorkflowSession - ): Unit = Unit + ): WorkflowLocal = proceed(workflowNodeScope, parentLocal) /** * Intercepts calls to [StatefulWorkflow.initialState]. @@ -72,9 +74,10 @@ public interface WorkflowInterceptor { public fun onInitialState( props: P, snapshot: Snapshot?, - proceed: (P, Snapshot?) -> S, + workflowLocal: WorkflowLocal, + proceed: (P, Snapshot?, WorkflowLocal) -> S, session: WorkflowSession - ): S = proceed(props, snapshot) + ): S = proceed(props, snapshot, workflowLocal) /** * Intercepts calls to [StatefulWorkflow.onPropsChanged]. @@ -148,6 +151,15 @@ public interface WorkflowInterceptor { */ public val sessionId: Long + /** + * A map of non-state objects that have been 'computed' within the scope of this session for use + * by it and its children. + * + * [EmptyWorkflowLocal] default so it does not need to be overridden for test sessions. + */ + public val workflowLocal: WorkflowLocal + get() = EmptyWorkflowLocal + /** The parent [WorkflowSession] of this workflow, or null if this is the root workflow. */ public val parent: WorkflowSession? @@ -266,10 +278,17 @@ internal fun WorkflowInterceptor.intercept( workflow } else { object : StatefulWorkflow() { + override fun nodeCreated( + workflowNodeScope: CoroutineScope, + parentLocal: WorkflowLocal + ): WorkflowLocal = + onNodeCreated(workflowNodeScope, parentLocal, workflow::nodeCreated, workflowSession) + override fun initialState( props: P, - snapshot: Snapshot? - ): S = onInitialState(props, snapshot, workflow::initialState, workflowSession) + snapshot: Snapshot?, + workflowLocal: WorkflowLocal + ): S = onInitialState(props, snapshot, workflowLocal, workflow::initialState, workflowSession) override fun onPropsChanged( old: P, @@ -304,6 +323,8 @@ private class InterceptedRenderContext( private val baseRenderContext: BaseRenderContext, private val interceptor: RenderContextInterceptor ) : BaseRenderContext, Sink> { + + override val workflowLocal: WorkflowLocal = baseRenderContext.workflowLocal override val actionSink: Sink> get() = this override fun send(value: WorkflowAction) { diff --git a/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/internal/ChainedWorkflowInterceptor.kt b/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/internal/ChainedWorkflowInterceptor.kt index 0fef705106..b237f3fd3f 100644 --- a/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/internal/ChainedWorkflowInterceptor.kt +++ b/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/internal/ChainedWorkflowInterceptor.kt @@ -10,6 +10,7 @@ import com.squareup.workflow1.WorkflowAction import com.squareup.workflow1.WorkflowInterceptor import com.squareup.workflow1.WorkflowInterceptor.RenderContextInterceptor import com.squareup.workflow1.WorkflowInterceptor.WorkflowSession +import com.squareup.workflow1.WorkflowLocal import kotlinx.coroutines.CoroutineScope internal fun List.chained(): WorkflowInterceptor = @@ -23,25 +24,33 @@ internal class ChainedWorkflowInterceptor( private val interceptors: List ) : WorkflowInterceptor { - override fun onSessionStarted( - workflowScope: CoroutineScope, + override fun onNodeCreated( + workflowNodeScope: CoroutineScope, + parentLocal: WorkflowLocal, + proceed: (CoroutineScope, WorkflowLocal) -> WorkflowLocal, session: WorkflowSession - ) { - interceptors.forEach { it.onSessionStarted(workflowScope, session) } + ): WorkflowLocal { + val chainedProceed = interceptors.foldRight(proceed) { workflowInterceptor, proceedAcc -> + { workflowNodeScope, parentLocal -> + workflowInterceptor.onNodeCreated(workflowNodeScope, parentLocal, proceedAcc, session) + } + } + return chainedProceed(workflowNodeScope, parentLocal) } override fun onInitialState( props: P, snapshot: Snapshot?, - proceed: (P, Snapshot?) -> S, + workflowLocal: WorkflowLocal, + proceed: (P, Snapshot?, WorkflowLocal) -> S, session: WorkflowSession ): S { val chainedProceed = interceptors.foldRight(proceed) { workflowInterceptor, proceedAcc -> - { props, snapshot -> - workflowInterceptor.onInitialState(props, snapshot, proceedAcc, session) + { props, snapshot, workflowLocal -> + workflowInterceptor.onInitialState(props, snapshot, workflowLocal, proceedAcc, session) } } - return chainedProceed(props, snapshot) + return chainedProceed(props, snapshot, workflowLocal) } override fun onPropsChanged( diff --git a/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/internal/RealRenderContext.kt b/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/internal/RealRenderContext.kt index f4572f7ef4..f99ac87fb4 100644 --- a/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/internal/RealRenderContext.kt +++ b/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/internal/RealRenderContext.kt @@ -4,13 +4,15 @@ import com.squareup.workflow1.BaseRenderContext import com.squareup.workflow1.Sink import com.squareup.workflow1.Workflow import com.squareup.workflow1.WorkflowAction +import com.squareup.workflow1.WorkflowLocal import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.SendChannel internal class RealRenderContext( private val renderer: Renderer, private val sideEffectRunner: SideEffectRunner, - private val eventActionsChannel: SendChannel> + private val eventActionsChannel: SendChannel>, + override val workflowLocal: WorkflowLocal ) : BaseRenderContext, Sink> { interface Renderer { diff --git a/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/internal/WorkflowNode.kt b/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/internal/WorkflowNode.kt index 22f008068b..b89c871aed 100644 --- a/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/internal/WorkflowNode.kt +++ b/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/internal/WorkflowNode.kt @@ -2,6 +2,7 @@ package com.squareup.workflow1.internal import com.squareup.workflow1.ActionApplied import com.squareup.workflow1.ActionProcessingResult +import com.squareup.workflow1.EmptyWorkflowLocal import com.squareup.workflow1.NoopWorkflowInterceptor import com.squareup.workflow1.RenderContext import com.squareup.workflow1.RuntimeConfig @@ -82,18 +83,25 @@ internal class WorkflowNode( Channel>(capacity = UNLIMITED) private var state: StateT + // Intercept to use for nodeCreated and initialState + private val interceptedWorkflow = interceptor.intercept(workflow, this) + override val workflowLocal = + interceptedWorkflow.nodeCreated(this, parent?.workflowLocal ?: EmptyWorkflowLocal) + private val baseRenderContext = RealRenderContext( renderer = subtreeManager, sideEffectRunner = this, - eventActionsChannel = eventActionsChannel + eventActionsChannel = eventActionsChannel, + workflowLocal = workflowLocal ) private val context = RenderContext(baseRenderContext, workflow) init { - interceptor.onSessionStarted(this, this) - - state = interceptor.intercept(workflow, this) - .initialState(initialProps, snapshot?.workflowSnapshot) + state = interceptedWorkflow.initialState( + initialProps, + snapshot?.workflowSnapshot, + workflowLocal + ) } override fun toString(): String { @@ -203,10 +211,13 @@ internal class WorkflowNode( workflow: StatefulWorkflow, props: PropsT ): RenderingT { - updatePropsAndState(workflow, props) + // We are passed in the workflow instance, so we intercept again here, rather than using the + // class val. + val interceptedWorkflowAfterStateType = interceptor.intercept(workflow, this) + updatePropsAndState(interceptedWorkflowAfterStateType, props) baseRenderContext.unfreeze() - val rendering = interceptor.intercept(workflow, this) + val rendering = interceptedWorkflowAfterStateType .render(props, state, context) baseRenderContext.freeze() @@ -225,7 +236,7 @@ internal class WorkflowNode( newProps: PropsT ) { if (newProps != lastProps) { - val newState = interceptor.intercept(workflow, this) + val newState = workflow .onPropsChanged(lastProps, newProps, state) state = newState } diff --git a/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/RenderWorkflowInTest.kt b/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/RenderWorkflowInTest.kt index 4deb51634a..9b706072fb 100644 --- a/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/RenderWorkflowInTest.kt +++ b/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/RenderWorkflowInTest.kt @@ -226,14 +226,13 @@ class RenderWorkflowInTest { }, snapshot = { state -> Snapshot.write { it.writeUtf8WithLength(state) } - }, - render = { _, renderState -> - Pair( - renderState, - { newState -> actionSink.send(action { state = newState }) } - ) } - ) + ) { _, renderState -> + Pair( + renderState, + { newState -> actionSink.send(action { state = newState }) } + ) + } val props = MutableStateFlow(Unit) val renderings = renderWorkflowIn( workflow = workflow, @@ -291,12 +290,11 @@ class RenderWorkflowInTest { snapped = true ByteString.of(1) } - }, - render = { _, renderState -> - sink = actionSink.contraMap { action { state = it } } - renderState } - ) + ) { _, renderState -> + sink = actionSink.contraMap { action { state = it } } + renderState + } val props = MutableStateFlow(Unit) val renderings = renderWorkflowIn( workflow = workflow, @@ -871,9 +869,8 @@ class RenderWorkflowInTest { throw ExpectedException() } }, - initialState = { _, _ -> }, - render = { _, _ -> } - ) + initialState = { _, _ -> } + ) { _, _ -> } val props = MutableStateFlow(0) val uncaughtExceptions = mutableListOf() val exceptionHandler = CoroutineExceptionHandler { _, throwable -> diff --git a/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/SimpleLoggingWorkflowInterceptorTest.kt b/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/SimpleLoggingWorkflowInterceptorTest.kt index 589dcab1e9..adb416b5a7 100644 --- a/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/SimpleLoggingWorkflowInterceptorTest.kt +++ b/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/SimpleLoggingWorkflowInterceptorTest.kt @@ -14,7 +14,12 @@ internal class SimpleLoggingWorkflowInterceptorTest { @Test fun onSessionStarted_handles_logging_exceptions() { val interceptor = ErrorLoggingInterceptor() val scope = CoroutineScope(EmptyCoroutineContext) - interceptor.onSessionStarted(scope, TestWorkflowSession) + interceptor.onNodeCreated( + scope, + EmptyWorkflowLocal, + { _, _ -> EmptyWorkflowLocal }, + TestWorkflowSession + ) scope.cancel() assertEquals(ErrorLoggingInterceptor.EXPECTED_ERRORS, interceptor.errors) @@ -22,7 +27,7 @@ internal class SimpleLoggingWorkflowInterceptorTest { @Test fun onInitialState_handles_logging_exceptions() { val interceptor = ErrorLoggingInterceptor() - interceptor.onInitialState(Unit, null, { _, _ -> }, TestWorkflowSession) + interceptor.onInitialState(Unit, null, EmptyWorkflowLocal, { _, _, _ -> }, TestWorkflowSession) assertEquals(ErrorLoggingInterceptor.EXPECTED_ERRORS, interceptor.errors) } @@ -77,7 +82,6 @@ internal class SimpleLoggingWorkflowInterceptorTest { } private object TestWorkflowSession : WorkflowSession { - @OptIn(ExperimentalStdlibApi::class) override val identifier: WorkflowIdentifier = unsnapshottableIdentifier(typeOf()) override val renderKey: String get() = "key" override val sessionId: Long get() = 42 diff --git a/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/WorkflowInterceptorTest.kt b/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/WorkflowInterceptorTest.kt index b437dcc74c..9f5c24905a 100644 --- a/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/WorkflowInterceptorTest.kt +++ b/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/WorkflowInterceptorTest.kt @@ -34,7 +34,7 @@ internal class WorkflowInterceptorTest { val recorder = RecordingWorkflowInterceptor() val intercepted = recorder.intercept(TestWorkflow, TestWorkflow.session) - val state = intercepted.initialState("props", Snapshot.of("snapshot")) + val state = intercepted.initialState("props", Snapshot.of("snapshot"), EmptyWorkflowLocal) assertEquals("props|snapshot", state) assertEquals(listOf("BEGIN|onInitialState", "END|onInitialState"), recorder.consumeEventNames()) @@ -94,6 +94,7 @@ internal class WorkflowInterceptorTest { val actions = mutableListOf>() val fakeContext = object : BaseRenderContext { + override val actionSink: Sink> = Sink { value -> actions += value } @@ -222,7 +223,8 @@ internal class WorkflowInterceptorTest { private object TestWorkflow : StatefulWorkflow() { override fun initialState( props: String, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): String = "$props|${snapshot?.bytes?.parse { it.readUtf8() }}" override fun onPropsChanged( @@ -244,7 +246,8 @@ internal class WorkflowInterceptorTest { private object TestActionWorkflow : StatefulWorkflow() { override fun initialState( props: String, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ) = "" override fun render( @@ -267,7 +270,8 @@ internal class WorkflowInterceptorTest { ) : StatefulWorkflow() { override fun initialState( props: String, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ) = "" override fun render( diff --git a/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/ChainedWorkflowInterceptorTest.kt b/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/ChainedWorkflowInterceptorTest.kt index 266ae5ca33..cca0324989 100644 --- a/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/ChainedWorkflowInterceptorTest.kt +++ b/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/ChainedWorkflowInterceptorTest.kt @@ -3,6 +3,7 @@ package com.squareup.workflow1.internal import com.squareup.workflow1.BaseRenderContext +import com.squareup.workflow1.EmptyWorkflowLocal import com.squareup.workflow1.NoopWorkflowInterceptor import com.squareup.workflow1.RuntimeConfig import com.squareup.workflow1.RuntimeConfigOptions @@ -14,6 +15,7 @@ import com.squareup.workflow1.WorkflowIdentifier import com.squareup.workflow1.WorkflowInterceptor import com.squareup.workflow1.WorkflowInterceptor.RenderContextInterceptor import com.squareup.workflow1.WorkflowInterceptor.WorkflowSession +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.identifier import com.squareup.workflow1.parse import com.squareup.workflow1.rendering @@ -62,31 +64,42 @@ internal class ChainedWorkflowInterceptorTest { fun chains_calls_to_onInstanceStarted_in_left_to_right_order() = runTest { val events = mutableListOf() val interceptor1 = object : WorkflowInterceptor { - override fun onSessionStarted( - workflowScope: CoroutineScope, + override fun onNodeCreated( + workflowNodeScope: CoroutineScope, + parentLocal: WorkflowLocal, + proceed: (CoroutineScope, WorkflowLocal) -> WorkflowLocal, session: WorkflowSession - ) { + ): WorkflowLocal { events += "started1" - workflowScope.coroutineContext[Job]!!.invokeOnCompletion { + workflowNodeScope.coroutineContext[Job]!!.invokeOnCompletion { events += "cancelled1" } + return parentLocal } } val interceptor2 = object : WorkflowInterceptor { - override fun onSessionStarted( - workflowScope: CoroutineScope, + override fun onNodeCreated( + workflowNodeScope: CoroutineScope, + parentLocal: WorkflowLocal, + proceed: (CoroutineScope, WorkflowLocal) -> WorkflowLocal, session: WorkflowSession - ) { + ): WorkflowLocal { events += "started2" - workflowScope.coroutineContext[Job]!!.invokeOnCompletion { + workflowNodeScope.coroutineContext[Job]!!.invokeOnCompletion { events += "cancelled2" } + return parentLocal } } val chained = listOf(interceptor1, interceptor2).chained() launch { - chained.onSessionStarted(this, TestSession) + chained.onNodeCreated( + this, + EmptyWorkflowLocal, + { _, parentLocal -> parentLocal }, + TestSession + ) } advanceUntilIdle() @@ -98,13 +111,15 @@ internal class ChainedWorkflowInterceptorTest { override fun onInitialState( props: P, snapshot: Snapshot?, - proceed: (P, Snapshot?) -> S, + workflowLocal: WorkflowLocal, + proceed: (P, Snapshot?, WorkflowLocal) -> S, session: WorkflowSession ): S = ( "r1: " + proceed( "props1: $props" as P, - Snapshot.of("snap1: ${snapshot.readUtf8()}") + Snapshot.of("snap1: ${snapshot.readUtf8()}"), + EmptyWorkflowLocal ) ) as S } @@ -112,24 +127,33 @@ internal class ChainedWorkflowInterceptorTest { override fun onInitialState( props: P, snapshot: Snapshot?, - proceed: (P, Snapshot?) -> S, + workflowLocal: WorkflowLocal, + proceed: (P, Snapshot?, WorkflowLocal) -> S, session: WorkflowSession ): S = ( "r2: " + proceed( "props2: $props" as P, - Snapshot.of("snap2: ${snapshot.readUtf8()}") + Snapshot.of("snap2: ${snapshot.readUtf8()}"), + EmptyWorkflowLocal ) ) as S } val chained = listOf(interceptor1, interceptor2).chained() fun initialState( props: String, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): String = "($props|${snapshot.readUtf8()})" val finalState = - chained.onInitialState("props", Snapshot.of("snap"), ::initialState, TestSession) + chained.onInitialState( + "props", + Snapshot.of("snap"), + EmptyWorkflowLocal, + ::initialState, + TestSession + ) assertEquals("r1: r2: (props2: props1: props|snap2: snap1: snap)", finalState) } diff --git a/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/RealRenderContextTest.kt b/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/RealRenderContextTest.kt index 45ce2dc9a4..1e9900db6a 100644 --- a/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/RealRenderContextTest.kt +++ b/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/RealRenderContextTest.kt @@ -6,6 +6,7 @@ import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow import com.squareup.workflow1.Workflow import com.squareup.workflow1.WorkflowAction +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.applyTo import com.squareup.workflow1.internal.RealRenderContext.Renderer @@ -63,7 +64,8 @@ internal class RealRenderContextTest { private class TestWorkflow : StatefulWorkflow() { override fun initialState( props: String, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): String = fail() override fun render( diff --git a/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/SubtreeManagerTest.kt b/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/SubtreeManagerTest.kt index c8e375a2a7..e7a94143f9 100644 --- a/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/SubtreeManagerTest.kt +++ b/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/SubtreeManagerTest.kt @@ -9,6 +9,7 @@ import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow import com.squareup.workflow1.TreeSnapshot import com.squareup.workflow1.WorkflowAction +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.WorkflowOutput import com.squareup.workflow1.action import com.squareup.workflow1.applyTo @@ -43,7 +44,8 @@ internal class SubtreeManagerTest { override fun initialState( props: String, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): String { started++ return "initialState:$props" @@ -72,7 +74,8 @@ internal class SubtreeManagerTest { override fun initialState( props: Unit, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ) { if (snapshot != null) restores++ } diff --git a/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/WorkflowNodeTest.kt b/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/WorkflowNodeTest.kt index 025ec7beaa..cf5bd85a2d 100644 --- a/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/WorkflowNodeTest.kt +++ b/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/WorkflowNodeTest.kt @@ -19,6 +19,7 @@ import com.squareup.workflow1.WorkflowIdentifier import com.squareup.workflow1.WorkflowInterceptor import com.squareup.workflow1.WorkflowInterceptor.RenderContextInterceptor import com.squareup.workflow1.WorkflowInterceptor.WorkflowSession +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.WorkflowOutput import com.squareup.workflow1.action import com.squareup.workflow1.contraMap @@ -72,7 +73,8 @@ internal class WorkflowNodeTest { override fun initialState( props: String, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): String { assertNull(snapshot) return "starting:$props" @@ -159,7 +161,8 @@ internal class WorkflowNodeTest { val workflow = object : StringEventWorkflow() { override fun initialState( props: String, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): String { assertNull(snapshot) return props @@ -201,7 +204,8 @@ internal class WorkflowNodeTest { val workflow = object : StringEventWorkflow() { override fun initialState( props: String, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): String { assertNull(snapshot) return props @@ -252,7 +256,8 @@ internal class WorkflowNodeTest { val workflow = object : StringWorkflow() { override fun initialState( props: String, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): String { assertNull(snapshot) return props @@ -559,13 +564,12 @@ internal class WorkflowNodeTest { .removePrefix("state:") } ?: props }, - render = { _, state -> state }, - snapshot = { state -> - Snapshot.write { - it.writeUtf8WithLength("state:$state") - } + render = { _, state -> state } + ) { state -> + Snapshot.write { + it.writeUtf8WithLength("state:$state") } - ) + } val originalNode = WorkflowNode( workflow.id(), workflow, @@ -592,9 +596,8 @@ internal class WorkflowNodeTest { @Test fun snapshots_empty_without_children() { val workflow = Workflow.stateful( initialState = { props, snapshot -> snapshot?.bytes?.utf8() ?: props }, - render = { _, state -> state }, - snapshot = { Snapshot.of("restored") } - ) + render = { _, state -> state } + ) { Snapshot.of("restored") } val originalNode = WorkflowNode( workflow.id(), workflow, @@ -629,13 +632,12 @@ internal class WorkflowNodeTest { .also { state -> restoredChildState = state } } ?: props }, - render = { _, state -> state }, - snapshot = { state -> - Snapshot.write { - it.writeUtf8WithLength("child state:$state") - } + render = { _, state -> state } + ) { state -> + Snapshot.write { + it.writeUtf8WithLength("child state:$state") } - ) + } val parentWorkflow = Workflow.stateful( initialState = { props, snapshot -> snapshot?.bytes?.parse { @@ -644,13 +646,12 @@ internal class WorkflowNodeTest { .also { state -> restoredParentState = state } } ?: props }, - render = { _, state -> "$state|" + renderChild(childWorkflow, "child props") }, - snapshot = { state -> - Snapshot.write { - it.writeUtf8WithLength("parent state:$state") - } + render = { _, state -> "$state|" + renderChild(childWorkflow, "child props") } + ) { state -> + Snapshot.write { + it.writeUtf8WithLength("parent state:$state") } - ) + } val originalNode = WorkflowNode( parentWorkflow.id(), @@ -729,9 +730,8 @@ internal class WorkflowNodeTest { return@parse "props:$props|state:$deserialized" } ?: props }, - render = { _, state -> state }, - snapshot = { state -> Snapshot.write { it.writeUtf8WithLength(state) } } - ) + render = { _, state -> state } + ) { state -> Snapshot.write { it.writeUtf8WithLength(state) } } val originalNode = WorkflowNode( workflow.id(), workflow, @@ -795,13 +795,15 @@ internal class WorkflowNodeTest { lateinit var interceptedSession: WorkflowSession lateinit var cancellationException: Throwable val interceptor = object : WorkflowInterceptor { - override fun onSessionStarted( - workflowScope: CoroutineScope, + override fun onNodeCreated( + workflowNodeScope: CoroutineScope, + parentLocal: WorkflowLocal, + proceed: (CoroutineScope, WorkflowLocal) -> WorkflowLocal, session: WorkflowSession - ) { - interceptedScope = workflowScope + ): WorkflowLocal { + interceptedScope = workflowNodeScope interceptedSession = session - workflowScope.coroutineContext[Job]!!.invokeOnCompletion { + workflowNodeScope.coroutineContext[Job]!!.invokeOnCompletion { cancellationException = it!! } } @@ -836,13 +838,15 @@ internal class WorkflowNodeTest { lateinit var interceptedSession: WorkflowSession lateinit var cancellationException: Throwable val interceptor = object : WorkflowInterceptor { - override fun onSessionStarted( - workflowScope: CoroutineScope, + override fun onNodeCreated( + workflowNodeScope: CoroutineScope, + parentLocal: WorkflowLocal, + proceed: (CoroutineScope, WorkflowLocal) -> WorkflowLocal, session: WorkflowSession - ) { - interceptedScope = workflowScope + ): WorkflowLocal { + interceptedScope = workflowNodeScope interceptedSession = session - workflowScope.coroutineContext[Job]!!.invokeOnCompletion { + workflowNodeScope.coroutineContext[Job]!!.invokeOnCompletion { cancellationException = it!! } } @@ -880,7 +884,8 @@ internal class WorkflowNodeTest { override fun onInitialState( props: P, snapshot: Snapshot?, - proceed: (P, Snapshot?) -> S, + workflowLocal: WorkflowLocal, + proceed: (P, Snapshot?, WorkflowLocal) -> S, session: WorkflowSession ): S { interceptedProps = props as String @@ -1025,9 +1030,8 @@ internal class WorkflowNodeTest { } val workflow = Workflow.stateful( initialState = { _, _ -> "state" }, - render = { _, state -> state }, - snapshot = { state -> Snapshot.of("snapshot($state)") } - ) + render = { _, state -> state } + ) { state -> Snapshot.of("snapshot($state)") } val node = WorkflowNode( id = workflow.id(key = "foo"), workflow = workflow.asStatefulWorkflow(), @@ -1066,9 +1070,8 @@ internal class WorkflowNodeTest { } val workflow = Workflow.stateful( initialState = { _, _ -> "state" }, - render = { _, state -> state }, - snapshot = { null } - ) + render = { _, state -> state } + ) { null } val node = WorkflowNode( id = workflow.id(key = "foo"), workflow = workflow.asStatefulWorkflow(), diff --git a/workflow-testing/api/workflow-testing.api b/workflow-testing/api/workflow-testing.api index 5e4778bc9f..2b449fb49e 100644 --- a/workflow-testing/api/workflow-testing.api +++ b/workflow-testing/api/workflow-testing.api @@ -1,10 +1,10 @@ public final class com/squareup/workflow1/testing/RenderIdempotencyChecker : com/squareup/workflow1/WorkflowInterceptor { public static final field INSTANCE Lcom/squareup/workflow1/testing/RenderIdempotencyChecker; - public fun onInitialState (Ljava/lang/Object;Lcom/squareup/workflow1/Snapshot;Lkotlin/jvm/functions/Function2;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object; + public fun onInitialState (Ljava/lang/Object;Lcom/squareup/workflow1/Snapshot;Lcom/squareup/workflow1/LocalMap;Lkotlin/jvm/functions/Function3;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object; + public fun onNodeCreated (Lkotlinx/coroutines/CoroutineScope;Lcom/squareup/workflow1/LocalMap;Lkotlin/jvm/functions/Function2;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Lcom/squareup/workflow1/LocalMap; public fun onPropsChanged (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function3;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object; public fun onRender (Ljava/lang/Object;Ljava/lang/Object;Lcom/squareup/workflow1/BaseRenderContext;Lkotlin/jvm/functions/Function3;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object; public fun onRenderAndSnapshot (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Lcom/squareup/workflow1/RenderingAndSnapshot; - public fun onSessionStarted (Lkotlinx/coroutines/CoroutineScope;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)V public fun onSnapshotState (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Lcom/squareup/workflow1/Snapshot; public fun onSnapshotStateWithChildren (Lkotlin/jvm/functions/Function0;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Lcom/squareup/workflow1/TreeSnapshot; } diff --git a/workflow-testing/src/main/java/com/squareup/workflow1/testing/RenderTester.kt b/workflow-testing/src/main/java/com/squareup/workflow1/testing/RenderTester.kt index d9dc8f565b..4200474557 100644 --- a/workflow-testing/src/main/java/com/squareup/workflow1/testing/RenderTester.kt +++ b/workflow-testing/src/main/java/com/squareup/workflow1/testing/RenderTester.kt @@ -1,6 +1,7 @@ package com.squareup.workflow1.testing import com.squareup.workflow1.ActionApplied +import com.squareup.workflow1.EmptyWorkflowLocal import com.squareup.workflow1.StatefulWorkflow import com.squareup.workflow1.Workflow import com.squareup.workflow1.WorkflowAction @@ -26,7 +27,7 @@ public fun Workflow.t val statefulWorkflow = asStatefulWorkflow() as StatefulWorkflow return statefulWorkflow.testRender( props = props, - initialState = statefulWorkflow.initialState(props, null) + initialState = statefulWorkflow.initialState(props, null, EmptyWorkflowLocal) ) as RenderTester } diff --git a/workflow-testing/src/main/java/com/squareup/workflow1/testing/WorkflowTestRuntime.kt b/workflow-testing/src/main/java/com/squareup/workflow1/testing/WorkflowTestRuntime.kt index 7131c52de1..86e1bc04ff 100644 --- a/workflow-testing/src/main/java/com/squareup/workflow1/testing/WorkflowTestRuntime.kt +++ b/workflow-testing/src/main/java/com/squareup/workflow1/testing/WorkflowTestRuntime.kt @@ -9,6 +9,7 @@ import com.squareup.workflow1.TreeSnapshot import com.squareup.workflow1.Workflow import com.squareup.workflow1.WorkflowInterceptor import com.squareup.workflow1.WorkflowInterceptor.WorkflowSession +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.config.JvmTestRuntimeConfigTools import com.squareup.workflow1.internal.util.UncaughtExceptionGuard import com.squareup.workflow1.renderWorkflowIn @@ -308,13 +309,14 @@ private fun WorkflowTestParams<*>.createInterceptors(): List onInitialState( props: P, snapshot: Snapshot?, - proceed: (P, Snapshot?) -> S, + workflowLocal: WorkflowLocal, + proceed: (P, Snapshot?, WorkflowLocal) -> S, session: WorkflowSession ): S { return if (session.parent == null) { startFrom.state as S } else { - proceed(props, snapshot) + proceed(props, snapshot, workflowLocal) } } } diff --git a/workflow-testing/src/test/java/com/squareup/workflow1/SnapshottingIntegrationTest.kt b/workflow-testing/src/test/java/com/squareup/workflow1/SnapshottingIntegrationTest.kt index 307d999078..913f2dda8b 100644 --- a/workflow-testing/src/test/java/com/squareup/workflow1/SnapshottingIntegrationTest.kt +++ b/workflow-testing/src/test/java/com/squareup/workflow1/SnapshottingIntegrationTest.kt @@ -136,13 +136,12 @@ class SnapshottingIntegrationTest { initialState = { props, _ -> props }, onPropsChanged = { _, new, _ -> new }, // Return an event handler that can be used to trigger new renderings. - render = { _, _ -> { actionSink.send(noAction()) } }, - snapshot = { state -> - Snapshot.write { - it.writeUtf8WithLength(state) - } + render = { _, _ -> { actionSink.send(noAction()) } } + ) { state -> + Snapshot.write { + it.writeUtf8WithLength(state) } - ) + } // This test specifically needs to test snapshots from a non-flat workflow tree. val root = Workflow.stateless Unit> { renderChild(workflow, it) diff --git a/workflow-testing/src/test/java/com/squareup/workflow1/TreeWorkflow.kt b/workflow-testing/src/test/java/com/squareup/workflow1/TreeWorkflow.kt index ad9c82298e..025d66a644 100644 --- a/workflow-testing/src/test/java/com/squareup/workflow1/TreeWorkflow.kt +++ b/workflow-testing/src/test/java/com/squareup/workflow1/TreeWorkflow.kt @@ -30,7 +30,8 @@ internal class TreeWorkflow( override fun initialState( props: String, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): String = snapshot?.bytes?.parse { it.readUtf8WithLength() } ?: props diff --git a/workflow-testing/src/test/java/com/squareup/workflow1/testing/RealRenderTesterTest.kt b/workflow-testing/src/test/java/com/squareup/workflow1/testing/RealRenderTesterTest.kt index 0b4c2e10c0..3a0e756c94 100644 --- a/workflow-testing/src/test/java/com/squareup/workflow1/testing/RealRenderTesterTest.kt +++ b/workflow-testing/src/test/java/com/squareup/workflow1/testing/RealRenderTesterTest.kt @@ -11,6 +11,7 @@ import com.squareup.workflow1.Workflow import com.squareup.workflow1.WorkflowAction import com.squareup.workflow1.WorkflowAction.Companion.noAction import com.squareup.workflow1.WorkflowIdentifier +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.WorkflowOutput import com.squareup.workflow1.action import com.squareup.workflow1.asWorker @@ -1309,7 +1310,8 @@ internal class RealRenderTesterTest { val workflow = object : StatefulWorkflow() { override fun initialState( props: String, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): Double = throw NotImplementedError() override fun render( @@ -1349,7 +1351,8 @@ internal class RealRenderTesterTest { class TestWorkflow : StatefulWorkflow() { override fun initialState( props: String, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): Double = throw NotImplementedError() override fun render( diff --git a/workflow-testing/src/test/java/com/squareup/workflow1/testing/WorkflowTestRuntimeTest.kt b/workflow-testing/src/test/java/com/squareup/workflow1/testing/WorkflowTestRuntimeTest.kt index 2708b1a81a..baa14efbad 100644 --- a/workflow-testing/src/test/java/com/squareup/workflow1/testing/WorkflowTestRuntimeTest.kt +++ b/workflow-testing/src/test/java/com/squareup/workflow1/testing/WorkflowTestRuntimeTest.kt @@ -95,9 +95,8 @@ internal class WorkflowTestRuntimeTest { assertNull(snapshot) throw ExpectedException() }, - render = { _, _ -> fail() }, - snapshot = { fail() } - ) + render = { _, _ -> fail() } + ) { fail() } rethrowingUncaughtExceptions { assertFailsWith { diff --git a/workflow-tracing/api/workflow-tracing.api b/workflow-tracing/api/workflow-tracing.api index df1698a239..4f2fb55fe5 100644 --- a/workflow-tracing/api/workflow-tracing.api +++ b/workflow-tracing/api/workflow-tracing.api @@ -12,11 +12,11 @@ public final class com/squareup/workflow1/diagnostic/tracing/RuntimeMemoryStats public final class com/squareup/workflow1/diagnostic/tracing/TracingWorkflowInterceptor : com/squareup/workflow1/WorkflowInterceptor { public fun (Lcom/squareup/workflow1/diagnostic/tracing/MemoryStats;Lkotlin/jvm/functions/Function2;)V public synthetic fun (Lcom/squareup/workflow1/diagnostic/tracing/MemoryStats;Lkotlin/jvm/functions/Function2;ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public fun onInitialState (Ljava/lang/Object;Lcom/squareup/workflow1/Snapshot;Lkotlin/jvm/functions/Function2;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object; + public fun onInitialState (Ljava/lang/Object;Lcom/squareup/workflow1/Snapshot;Lcom/squareup/workflow1/LocalMap;Lkotlin/jvm/functions/Function3;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object; + public fun onNodeCreated (Lkotlinx/coroutines/CoroutineScope;Lcom/squareup/workflow1/LocalMap;Lkotlin/jvm/functions/Function2;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Lcom/squareup/workflow1/LocalMap; public fun onPropsChanged (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function3;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object; public fun onRender (Ljava/lang/Object;Ljava/lang/Object;Lcom/squareup/workflow1/BaseRenderContext;Lkotlin/jvm/functions/Function3;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object; public fun onRenderAndSnapshot (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Lcom/squareup/workflow1/RenderingAndSnapshot; - public fun onSessionStarted (Lkotlinx/coroutines/CoroutineScope;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)V public fun onSnapshotState (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Lcom/squareup/workflow1/Snapshot; public fun onSnapshotStateWithChildren (Lkotlin/jvm/functions/Function0;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Lcom/squareup/workflow1/TreeSnapshot; } diff --git a/workflow-tracing/src/main/java/com/squareup/workflow1/diagnostic/tracing/TracingWorkflowInterceptor.kt b/workflow-tracing/src/main/java/com/squareup/workflow1/diagnostic/tracing/TracingWorkflowInterceptor.kt index 0fb3bb3d72..992ba8f470 100644 --- a/workflow-tracing/src/main/java/com/squareup/workflow1/diagnostic/tracing/TracingWorkflowInterceptor.kt +++ b/workflow-tracing/src/main/java/com/squareup/workflow1/diagnostic/tracing/TracingWorkflowInterceptor.kt @@ -23,6 +23,7 @@ import com.squareup.workflow1.WorkflowIdentifierType.Unsnapshottable import com.squareup.workflow1.WorkflowInterceptor import com.squareup.workflow1.WorkflowInterceptor.RenderContextInterceptor import com.squareup.workflow1.WorkflowInterceptor.WorkflowSession +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.applyTo import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job @@ -123,11 +124,13 @@ public class TracingWorkflowInterceptor internal constructor( private val workflowNamesById = mutableMapOf() - override fun onSessionStarted( - workflowScope: CoroutineScope, + override fun onNodeCreated( + workflowNodeScope: CoroutineScope, + parentLocal: WorkflowLocal, + proceed: (CoroutineScope, WorkflowLocal) -> WorkflowLocal, session: WorkflowSession - ) { - val workflowJob = workflowScope.coroutineContext[Job]!! + ): WorkflowLocal { + val workflowJob = workflowNodeScope.coroutineContext[Job]!! // Invoke this before runtime logic since cancellation handlers are invoked in the same order // in which they were registered, and we want to emit workflow stopped before runtime stopped. @@ -136,20 +139,22 @@ public class TracingWorkflowInterceptor internal constructor( } if (session.parent == null) { - onRuntimeStarted(workflowScope, session.identifier.toLoggingName()) + onRuntimeStarted(workflowNodeScope, session.identifier.toLoggingName()) workflowJob.invokeOnCompletion { onRuntimeStopped() } } + return proceed(workflowNodeScope, parentLocal) } override fun onInitialState( props: P, snapshot: Snapshot?, - proceed: (P, Snapshot?) -> S, + workflowLocal: WorkflowLocal, + proceed: (P, Snapshot?, WorkflowLocal) -> S, session: WorkflowSession ): S { - val initialState = proceed(props, snapshot) + val initialState = proceed(props, snapshot, workflowLocal) onWorkflowStarted( workflowId = session.sessionId, diff --git a/workflow-tracing/src/test/java/com/squareup/workflow1/diagnostic/tracing/TracingWorkflowInterceptorTest.kt b/workflow-tracing/src/test/java/com/squareup/workflow1/diagnostic/tracing/TracingWorkflowInterceptorTest.kt index d3bc0fd065..fd01661499 100644 --- a/workflow-tracing/src/test/java/com/squareup/workflow1/diagnostic/tracing/TracingWorkflowInterceptorTest.kt +++ b/workflow-tracing/src/test/java/com/squareup/workflow1/diagnostic/tracing/TracingWorkflowInterceptorTest.kt @@ -4,6 +4,7 @@ import com.squareup.tracing.TimeMark import com.squareup.tracing.TraceEncoder import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.asWorker import com.squareup.workflow1.renderWorkflowIn @@ -101,7 +102,8 @@ internal class TracingWorkflowInterceptorTest { override fun initialState( props: Int, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): String { // Pretend to detect a garbage collection whenever a workflow starts. onGcDetected() diff --git a/workflow-ui/compose/api/compose.api b/workflow-ui/compose/api/compose.api index 3065c35e80..8b398d5a49 100644 --- a/workflow-ui/compose/api/compose.api +++ b/workflow-ui/compose/api/compose.api @@ -1,5 +1,5 @@ public abstract interface class com/squareup/workflow1/ui/compose/ComposeRendering : com/squareup/workflow1/ui/AndroidViewRendering { - public abstract fun Content (Lcom/squareup/workflow1/ui/ViewEnvironment;Landroidx/compose/runtime/Composer;I)V + public abstract fun Content (Lcom/squareup/workflow1/LocalMap;Landroidx/compose/runtime/Composer;I)V public abstract fun getViewFactory ()Lcom/squareup/workflow1/ui/ViewFactory; } @@ -12,7 +12,7 @@ public final class com/squareup/workflow1/ui/compose/ComposeRenderingKt { } public abstract interface class com/squareup/workflow1/ui/compose/ComposeScreen : com/squareup/workflow1/ui/AndroidScreen { - public abstract fun Content (Lcom/squareup/workflow1/ui/ViewEnvironment;Landroidx/compose/runtime/Composer;I)V + public abstract fun Content (Lcom/squareup/workflow1/LocalMap;Landroidx/compose/runtime/Composer;I)V public abstract fun getViewFactory ()Lcom/squareup/workflow1/ui/ScreenViewFactory; } @@ -27,8 +27,8 @@ public final class com/squareup/workflow1/ui/compose/ComposeScreenKt { public abstract class com/squareup/workflow1/ui/compose/ComposeScreenViewFactory : com/squareup/workflow1/ui/ScreenViewFactory { public static final field $stable I public fun ()V - public abstract fun Content (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroidx/compose/runtime/Composer;I)V - public final fun buildView (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;)Lcom/squareup/workflow1/ui/ScreenViewHolder; + public abstract fun Content (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/LocalMap;Landroidx/compose/runtime/Composer;I)V + public final fun buildView (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/LocalMap;Landroid/content/Context;Landroid/view/ViewGroup;)Lcom/squareup/workflow1/ui/ScreenViewHolder; } public final class com/squareup/workflow1/ui/compose/ComposeScreenViewFactoryKt { @@ -38,8 +38,8 @@ public final class com/squareup/workflow1/ui/compose/ComposeScreenViewFactoryKt public abstract class com/squareup/workflow1/ui/compose/ComposeViewFactory : com/squareup/workflow1/ui/ViewFactory { public static final field $stable I public fun ()V - public abstract fun Content (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroidx/compose/runtime/Composer;I)V - public final fun buildView (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View; + public abstract fun Content (Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Landroidx/compose/runtime/Composer;I)V + public final fun buildView (Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View; } public final class com/squareup/workflow1/ui/compose/ComposeViewFactoryKt { @@ -47,13 +47,13 @@ public final class com/squareup/workflow1/ui/compose/ComposeViewFactoryKt { } public final class com/squareup/workflow1/ui/compose/CompositionRootKt { + public static final fun withCompositionRoot (Lcom/squareup/workflow1/LocalMap;Lkotlin/jvm/functions/Function3;)Lcom/squareup/workflow1/LocalMap; public static final fun withCompositionRoot (Lcom/squareup/workflow1/ui/ScreenViewFactoryFinder;Lkotlin/jvm/functions/Function3;)Lcom/squareup/workflow1/ui/ScreenViewFactoryFinder; - public static final fun withCompositionRoot (Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function3;)Lcom/squareup/workflow1/ui/ViewEnvironment; public static final fun withCompositionRoot (Lcom/squareup/workflow1/ui/ViewRegistry;Lkotlin/jvm/functions/Function3;)Lcom/squareup/workflow1/ui/ViewRegistry; } public final class com/squareup/workflow1/ui/compose/LegacyWorkflowRenderingKt { - public static final fun WorkflowRendering (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;II)V + public static final fun WorkflowRendering (Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;II)V } public final class com/squareup/workflow1/ui/compose/RenderAsStateKt { @@ -65,6 +65,6 @@ public final class com/squareup/workflow1/ui/compose/TextControllerAsMutableStat } public final class com/squareup/workflow1/ui/compose/WorkflowRenderingKt { - public static final fun WorkflowRendering (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;II)V + public static final fun WorkflowRendering (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/LocalMap;Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;II)V } diff --git a/workflow-ui/compose/src/androidTest/java/com/squareup/workflow1/ui/compose/RenderAsStateTest.kt b/workflow-ui/compose/src/androidTest/java/com/squareup/workflow1/ui/compose/RenderAsStateTest.kt index e060be47e5..e2f9a50888 100644 --- a/workflow-ui/compose/src/androidTest/java/com/squareup/workflow1/ui/compose/RenderAsStateTest.kt +++ b/workflow-ui/compose/src/androidTest/java/com/squareup/workflow1/ui/compose/RenderAsStateTest.kt @@ -17,6 +17,7 @@ import com.google.common.truth.Truth.assertThat import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow import com.squareup.workflow1.Workflow +import com.squareup.workflow1.WorkflowLocal import com.squareup.workflow1.action import com.squareup.workflow1.parse import com.squareup.workflow1.readUtf8WithLength @@ -368,7 +369,8 @@ internal class RenderAsStateTest { override fun initialState( props: Unit, - snapshot: Snapshot? + snapshot: Snapshot?, + workflowLocal: WorkflowLocal ): String = snapshot?.bytes?.parse { it.readUtf8WithLength() } ?: "" override fun render( diff --git a/workflow-ui/container-android/api/container-android.api b/workflow-ui/container-android/api/container-android.api index fb56d04319..6f1016ad4c 100644 --- a/workflow-ui/container-android/api/container-android.api +++ b/workflow-ui/container-android/api/container-android.api @@ -4,8 +4,8 @@ public final class com/squareup/workflow1/ui/backstack/BackStackContainer { } public final class com/squareup/workflow1/ui/backstack/BackStackContainer$Companion : com/squareup/workflow1/ui/ViewFactory { - public fun buildView (Lcom/squareup/workflow1/ui/backstack/BackStackScreen;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View; - public synthetic fun buildView (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View; + public fun buildView (Lcom/squareup/workflow1/ui/backstack/BackStackScreen;Lcom/squareup/workflow1/LocalMap;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View; + public synthetic fun buildView (Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View; public fun getType ()Lkotlin/reflect/KClass; } @@ -17,12 +17,12 @@ public final class com/squareup/workflow1/ui/modal/AlertContainer : com/squareup public fun (Landroid/content/Context;Landroid/util/AttributeSet;II)V public fun (Landroid/content/Context;Landroid/util/AttributeSet;III)V public synthetic fun (Landroid/content/Context;Landroid/util/AttributeSet;IIIILkotlin/jvm/internal/DefaultConstructorMarker;)V - public synthetic fun buildDialog (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;)Lcom/squareup/workflow1/ui/modal/ModalContainer$DialogRef; + public synthetic fun buildDialog (Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;)Lcom/squareup/workflow1/ui/modal/ModalContainer$DialogRef; } public final class com/squareup/workflow1/ui/modal/AlertContainer$Companion : com/squareup/workflow1/ui/ViewFactory { - public fun buildView (Lcom/squareup/workflow1/ui/modal/AlertContainerScreen;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View; - public synthetic fun buildView (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View; + public fun buildView (Lcom/squareup/workflow1/ui/modal/AlertContainerScreen;Lcom/squareup/workflow1/LocalMap;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View; + public synthetic fun buildView (Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View; public final fun customThemeBinding (I)Lcom/squareup/workflow1/ui/ViewFactory; public static synthetic fun customThemeBinding$default (Lcom/squareup/workflow1/ui/modal/AlertContainer$Companion;IILjava/lang/Object;)Lcom/squareup/workflow1/ui/ViewFactory; public fun getType ()Lkotlin/reflect/KClass; @@ -34,25 +34,25 @@ public abstract class com/squareup/workflow1/ui/modal/ModalContainer : android/w public fun (Landroid/content/Context;Landroid/util/AttributeSet;I)V public fun (Landroid/content/Context;Landroid/util/AttributeSet;II)V public synthetic fun (Landroid/content/Context;Landroid/util/AttributeSet;IIILkotlin/jvm/internal/DefaultConstructorMarker;)V - protected abstract fun buildDialog (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;)Lcom/squareup/workflow1/ui/modal/ModalContainer$DialogRef; + protected abstract fun buildDialog (Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;)Lcom/squareup/workflow1/ui/modal/ModalContainer$DialogRef; protected fun onAttachedToWindow ()V protected fun onDetachedFromWindow ()V protected fun onRestoreInstanceState (Landroid/os/Parcelable;)V protected fun onSaveInstanceState ()Landroid/os/Parcelable; - protected final fun update (Lcom/squareup/workflow1/ui/modal/HasModals;Lcom/squareup/workflow1/ui/ViewEnvironment;)V + protected final fun update (Lcom/squareup/workflow1/ui/modal/HasModals;Lcom/squareup/workflow1/LocalMap;)V protected abstract fun updateDialog (Lcom/squareup/workflow1/ui/modal/ModalContainer$DialogRef;)V } protected final class com/squareup/workflow1/ui/modal/ModalContainer$DialogRef { - public fun (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/app/Dialog;Ljava/lang/Object;)V - public synthetic fun (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/app/Dialog;Ljava/lang/Object;ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun copy (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/app/Dialog;Ljava/lang/Object;)Lcom/squareup/workflow1/ui/modal/ModalContainer$DialogRef; - public static synthetic fun copy$default (Lcom/squareup/workflow1/ui/modal/ModalContainer$DialogRef;Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/app/Dialog;Ljava/lang/Object;ILjava/lang/Object;)Lcom/squareup/workflow1/ui/modal/ModalContainer$DialogRef; + public fun (Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Landroid/app/Dialog;Ljava/lang/Object;)V + public synthetic fun (Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Landroid/app/Dialog;Ljava/lang/Object;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun copy (Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Landroid/app/Dialog;Ljava/lang/Object;)Lcom/squareup/workflow1/ui/modal/ModalContainer$DialogRef; + public static synthetic fun copy$default (Lcom/squareup/workflow1/ui/modal/ModalContainer$DialogRef;Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Landroid/app/Dialog;Ljava/lang/Object;ILjava/lang/Object;)Lcom/squareup/workflow1/ui/modal/ModalContainer$DialogRef; public fun equals (Ljava/lang/Object;)Z public final fun getDialog ()Landroid/app/Dialog; public final fun getExtra ()Ljava/lang/Object; public final fun getModalRendering ()Ljava/lang/Object; - public final fun getViewEnvironment ()Lcom/squareup/workflow1/ui/ViewEnvironment; + public final fun getViewEnvironment ()Lcom/squareup/workflow1/LocalMap; public fun hashCode ()I } @@ -63,7 +63,7 @@ public class com/squareup/workflow1/ui/modal/ModalViewContainer : com/squareup/w public fun (Landroid/content/Context;Landroid/util/AttributeSet;I)V public fun (Landroid/content/Context;Landroid/util/AttributeSet;II)V public synthetic fun (Landroid/content/Context;Landroid/util/AttributeSet;IIILkotlin/jvm/internal/DefaultConstructorMarker;)V - protected final fun buildDialog (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;)Lcom/squareup/workflow1/ui/modal/ModalContainer$DialogRef; + protected final fun buildDialog (Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;)Lcom/squareup/workflow1/ui/modal/ModalContainer$DialogRef; public fun buildDialogForView (Landroid/view/View;)Landroid/app/Dialog; protected fun updateDialog (Lcom/squareup/workflow1/ui/modal/ModalContainer$DialogRef;)V } @@ -73,8 +73,8 @@ public final class com/squareup/workflow1/ui/modal/ModalViewContainer$Companion public final class com/squareup/workflow1/ui/modal/ModalViewContainer$ModalViewFactory : com/squareup/workflow1/ui/ViewFactory { public fun (ILkotlin/reflect/KClass;)V - public fun buildView (Lcom/squareup/workflow1/ui/modal/HasModals;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View; - public synthetic fun buildView (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View; + public fun buildView (Lcom/squareup/workflow1/ui/modal/HasModals;Lcom/squareup/workflow1/LocalMap;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View; + public synthetic fun buildView (Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View; public fun getType ()Lkotlin/reflect/KClass; } diff --git a/workflow-ui/core-android/api/core-android.api b/workflow-ui/core-android/api/core-android.api index 007cdd5c2d..8323ab42b8 100644 --- a/workflow-ui/core-android/api/core-android.api +++ b/workflow-ui/core-android/api/core-android.api @@ -12,8 +12,8 @@ public abstract interface class com/squareup/workflow1/ui/AndroidScreen : com/sq } public final class com/squareup/workflow1/ui/AndroidViewRegistryKt { - public static final fun buildView (Lcom/squareup/workflow1/ui/ViewRegistry;Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;Lcom/squareup/workflow1/ui/ViewStarter;)Landroid/view/View; - public static synthetic fun buildView$default (Lcom/squareup/workflow1/ui/ViewRegistry;Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;Lcom/squareup/workflow1/ui/ViewStarter;ILjava/lang/Object;)Landroid/view/View; + public static final fun buildView (Lcom/squareup/workflow1/ui/ViewRegistry;Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Landroid/content/Context;Landroid/view/ViewGroup;Lcom/squareup/workflow1/ui/ViewStarter;)Landroid/view/View; + public static synthetic fun buildView$default (Lcom/squareup/workflow1/ui/ViewRegistry;Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Landroid/content/Context;Landroid/view/ViewGroup;Lcom/squareup/workflow1/ui/ViewStarter;ILjava/lang/Object;)Landroid/view/View; public static final fun getFactoryFor (Lcom/squareup/workflow1/ui/ViewRegistry;Lkotlin/reflect/KClass;)Lcom/squareup/workflow1/ui/ViewFactory; public static final fun getFactoryForRendering (Lcom/squareup/workflow1/ui/ViewRegistry;Ljava/lang/Object;)Lcom/squareup/workflow1/ui/ViewFactory; } @@ -38,7 +38,7 @@ public final class com/squareup/workflow1/ui/BackPressHandlerKt { public final class com/squareup/workflow1/ui/BuilderViewFactory : com/squareup/workflow1/ui/ViewFactory { public fun (Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function4;)V - public fun buildView (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View; + public fun buildView (Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View; public fun getType ()Lkotlin/reflect/KClass; } @@ -47,7 +47,7 @@ public final class com/squareup/workflow1/ui/DecorativeViewFactory : com/squareu public synthetic fun (Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow1/ui/ViewStarter;Lkotlin/jvm/functions/Function4;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun (Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function2;Lcom/squareup/workflow1/ui/ViewStarter;Lkotlin/jvm/functions/Function4;)V public synthetic fun (Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function2;Lcom/squareup/workflow1/ui/ViewStarter;Lkotlin/jvm/functions/Function4;ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public fun buildView (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View; + public fun buildView (Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View; public fun getType ()Lkotlin/reflect/KClass; } @@ -58,7 +58,7 @@ public final class com/squareup/workflow1/ui/EditTextsKt { public abstract interface class com/squareup/workflow1/ui/LayoutRunner { public static final field Companion Lcom/squareup/workflow1/ui/LayoutRunner$Companion; - public abstract fun showRendering (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;)V + public abstract fun showRendering (Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;)V } public final class com/squareup/workflow1/ui/LayoutRunner$Companion { @@ -66,17 +66,17 @@ public final class com/squareup/workflow1/ui/LayoutRunner$Companion { public final class com/squareup/workflow1/ui/LayoutRunnerViewFactory : com/squareup/workflow1/ui/ViewFactory { public fun (Lkotlin/reflect/KClass;ILkotlin/jvm/functions/Function1;)V - public fun buildView (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View; + public fun buildView (Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View; public fun getType ()Lkotlin/reflect/KClass; } public final class com/squareup/workflow1/ui/LayoutScreenViewFactory : com/squareup/workflow1/ui/ScreenViewFactory { public fun (Lkotlin/reflect/KClass;ILkotlin/jvm/functions/Function1;)V - public fun buildView (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;)Lcom/squareup/workflow1/ui/ScreenViewHolder; + public fun buildView (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/LocalMap;Landroid/content/Context;Landroid/view/ViewGroup;)Lcom/squareup/workflow1/ui/ScreenViewHolder; public fun getType ()Lkotlin/reflect/KClass; } -public final class com/squareup/workflow1/ui/OnBackPressedDispatcherOwnerKey : com/squareup/workflow1/ui/ViewEnvironmentKey { +public final class com/squareup/workflow1/ui/OnBackPressedDispatcherOwnerKey : com/squareup/workflow1/LocalMapKey { public static final field INSTANCE Lcom/squareup/workflow1/ui/OnBackPressedDispatcherOwnerKey; public fun getDefault ()Landroidx/activity/OnBackPressedDispatcherOwner; public synthetic fun getDefault ()Ljava/lang/Object; @@ -103,56 +103,56 @@ public final class com/squareup/workflow1/ui/ParcelableTextController$CREATOR : public abstract interface class com/squareup/workflow1/ui/ScreenViewFactory : com/squareup/workflow1/ui/ViewRegistry$Entry { public static final field Companion Lcom/squareup/workflow1/ui/ScreenViewFactory$Companion; - public abstract fun buildView (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;)Lcom/squareup/workflow1/ui/ScreenViewHolder; + public abstract fun buildView (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/LocalMap;Landroid/content/Context;Landroid/view/ViewGroup;)Lcom/squareup/workflow1/ui/ScreenViewHolder; } public final class com/squareup/workflow1/ui/ScreenViewFactory$Companion { } public final class com/squareup/workflow1/ui/ScreenViewFactory$DefaultImpls { - public static synthetic fun buildView$default (Lcom/squareup/workflow1/ui/ScreenViewFactory;Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;ILjava/lang/Object;)Lcom/squareup/workflow1/ui/ScreenViewHolder; + public static synthetic fun buildView$default (Lcom/squareup/workflow1/ui/ScreenViewFactory;Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/LocalMap;Landroid/content/Context;Landroid/view/ViewGroup;ILjava/lang/Object;)Lcom/squareup/workflow1/ui/ScreenViewHolder; } public abstract interface class com/squareup/workflow1/ui/ScreenViewFactoryFinder { public static final field Companion Lcom/squareup/workflow1/ui/ScreenViewFactoryFinder$Companion; - public abstract fun getViewFactoryForRendering (Lcom/squareup/workflow1/ui/ViewEnvironment;Lcom/squareup/workflow1/ui/Screen;)Lcom/squareup/workflow1/ui/ScreenViewFactory; + public abstract fun getViewFactoryForRendering (Lcom/squareup/workflow1/LocalMap;Lcom/squareup/workflow1/ui/Screen;)Lcom/squareup/workflow1/ui/ScreenViewFactory; } -public final class com/squareup/workflow1/ui/ScreenViewFactoryFinder$Companion : com/squareup/workflow1/ui/ViewEnvironmentKey { +public final class com/squareup/workflow1/ui/ScreenViewFactoryFinder$Companion : com/squareup/workflow1/LocalMapKey { public fun getDefault ()Lcom/squareup/workflow1/ui/ScreenViewFactoryFinder; public synthetic fun getDefault ()Ljava/lang/Object; } public final class com/squareup/workflow1/ui/ScreenViewFactoryFinder$DefaultImpls { - public static fun getViewFactoryForRendering (Lcom/squareup/workflow1/ui/ScreenViewFactoryFinder;Lcom/squareup/workflow1/ui/ViewEnvironment;Lcom/squareup/workflow1/ui/Screen;)Lcom/squareup/workflow1/ui/ScreenViewFactory; + public static fun getViewFactoryForRendering (Lcom/squareup/workflow1/ui/ScreenViewFactoryFinder;Lcom/squareup/workflow1/LocalMap;Lcom/squareup/workflow1/ui/Screen;)Lcom/squareup/workflow1/ui/ScreenViewFactory; } public final class com/squareup/workflow1/ui/ScreenViewFactoryKt { - public static final fun startShowing (Lcom/squareup/workflow1/ui/ScreenViewFactory;Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;Lcom/squareup/workflow1/ui/ViewStarter;)Lcom/squareup/workflow1/ui/ScreenViewHolder; - public static final fun startShowing (Lcom/squareup/workflow1/ui/ScreenViewHolder;Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;Lcom/squareup/workflow1/ui/ViewStarter;)V - public static synthetic fun startShowing$default (Lcom/squareup/workflow1/ui/ScreenViewFactory;Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;Lcom/squareup/workflow1/ui/ViewStarter;ILjava/lang/Object;)Lcom/squareup/workflow1/ui/ScreenViewHolder; - public static final fun toViewFactory (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;)Lcom/squareup/workflow1/ui/ScreenViewFactory; + public static final fun startShowing (Lcom/squareup/workflow1/ui/ScreenViewFactory;Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/LocalMap;Landroid/content/Context;Landroid/view/ViewGroup;Lcom/squareup/workflow1/ui/ViewStarter;)Lcom/squareup/workflow1/ui/ScreenViewHolder; + public static final fun startShowing (Lcom/squareup/workflow1/ui/ScreenViewHolder;Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/LocalMap;Lcom/squareup/workflow1/ui/ViewStarter;)V + public static synthetic fun startShowing$default (Lcom/squareup/workflow1/ui/ScreenViewFactory;Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/LocalMap;Landroid/content/Context;Landroid/view/ViewGroup;Lcom/squareup/workflow1/ui/ViewStarter;ILjava/lang/Object;)Lcom/squareup/workflow1/ui/ScreenViewHolder; + public static final fun toViewFactory (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/LocalMap;)Lcom/squareup/workflow1/ui/ScreenViewFactory; } public abstract interface class com/squareup/workflow1/ui/ScreenViewHolder { public static final field Companion Lcom/squareup/workflow1/ui/ScreenViewHolder$Companion; - public abstract fun getEnvironment ()Lcom/squareup/workflow1/ui/ViewEnvironment; + public abstract fun getEnvironment ()Lcom/squareup/workflow1/LocalMap; public abstract fun getRunner ()Lcom/squareup/workflow1/ui/ScreenViewRunner; public abstract fun getView ()Landroid/view/View; } public final class com/squareup/workflow1/ui/ScreenViewHolder$Companion { - public final fun invoke (Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/view/View;Lcom/squareup/workflow1/ui/ScreenViewRunner;)Lcom/squareup/workflow1/ui/ScreenViewHolder; + public final fun invoke (Lcom/squareup/workflow1/LocalMap;Landroid/view/View;Lcom/squareup/workflow1/ui/ScreenViewRunner;)Lcom/squareup/workflow1/ui/ScreenViewHolder; } public final class com/squareup/workflow1/ui/ScreenViewHolderKt { public static final fun canShow (Lcom/squareup/workflow1/ui/ScreenViewHolder;Lcom/squareup/workflow1/ui/Screen;)Z public static final fun getShowing (Lcom/squareup/workflow1/ui/ScreenViewHolder;)Lcom/squareup/workflow1/ui/Screen; - public static final fun show (Lcom/squareup/workflow1/ui/ScreenViewHolder;Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;)V + public static final fun show (Lcom/squareup/workflow1/ui/ScreenViewHolder;Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/LocalMap;)V } public abstract interface class com/squareup/workflow1/ui/ScreenViewRunner { - public abstract fun showRendering (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;)V + public abstract fun showRendering (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/LocalMap;)V } public final class com/squareup/workflow1/ui/SnapshotParcelsKt { @@ -171,33 +171,33 @@ public final class com/squareup/workflow1/ui/ViewBackHandlerKt { public final class com/squareup/workflow1/ui/ViewBindingScreenViewFactory : com/squareup/workflow1/ui/ScreenViewFactory { public fun (Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function1;)V - public fun buildView (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;)Lcom/squareup/workflow1/ui/ScreenViewHolder; + public fun buildView (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/LocalMap;Landroid/content/Context;Landroid/view/ViewGroup;)Lcom/squareup/workflow1/ui/ScreenViewHolder; public fun getType ()Lkotlin/reflect/KClass; } public final class com/squareup/workflow1/ui/ViewBindingViewFactory : com/squareup/workflow1/ui/ViewFactory { public fun (Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function1;)V - public fun buildView (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View; + public fun buildView (Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View; public fun getType ()Lkotlin/reflect/KClass; } public abstract interface class com/squareup/workflow1/ui/ViewFactory : com/squareup/workflow1/ui/ViewRegistry$Entry { - public abstract fun buildView (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View; + public abstract fun buildView (Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View; } public final class com/squareup/workflow1/ui/ViewFactory$DefaultImpls { - public static synthetic fun buildView$default (Lcom/squareup/workflow1/ui/ViewFactory;Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;ILjava/lang/Object;)Landroid/view/View; + public static synthetic fun buildView$default (Lcom/squareup/workflow1/ui/ViewFactory;Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Landroid/content/Context;Landroid/view/ViewGroup;ILjava/lang/Object;)Landroid/view/View; } public final class com/squareup/workflow1/ui/ViewShowRenderingKt { - public static final fun bindShowRendering (Landroid/view/View;Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function2;)V + public static final fun bindShowRendering (Landroid/view/View;Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Lkotlin/jvm/functions/Function2;)V public static final fun canShowRendering (Landroid/view/View;Ljava/lang/Object;)Z - public static final fun getEnvironment (Landroid/view/View;)Lcom/squareup/workflow1/ui/ViewEnvironment; - public static final fun getEnvironmentOrNull (Landroid/view/View;)Lcom/squareup/workflow1/ui/ViewEnvironment; + public static final fun getEnvironment (Landroid/view/View;)Lcom/squareup/workflow1/LocalMap; + public static final fun getEnvironmentOrNull (Landroid/view/View;)Lcom/squareup/workflow1/LocalMap; public static final fun getScreen (Landroid/view/View;)Lcom/squareup/workflow1/ui/Screen; public static final fun getScreenOrNull (Landroid/view/View;)Lcom/squareup/workflow1/ui/Screen; public static final fun getShowRendering (Landroid/view/View;)Lkotlin/jvm/functions/Function2; - public static final fun showRendering (Landroid/view/View;Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;)V + public static final fun showRendering (Landroid/view/View;Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;)V public static final fun start (Landroid/view/View;)V } @@ -208,35 +208,35 @@ public abstract interface class com/squareup/workflow1/ui/ViewStarter { public final class com/squareup/workflow1/ui/WorkflowLayout : android/widget/FrameLayout { public fun (Landroid/content/Context;Landroid/util/AttributeSet;)V public synthetic fun (Landroid/content/Context;Landroid/util/AttributeSet;ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun show (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;)V - public static synthetic fun show$default (Lcom/squareup/workflow1/ui/WorkflowLayout;Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;ILjava/lang/Object;)V - public final fun start (Landroidx/lifecycle/Lifecycle;Lkotlinx/coroutines/flow/Flow;Landroidx/lifecycle/Lifecycle$State;Lcom/squareup/workflow1/ui/ViewEnvironment;)V + public final fun show (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/LocalMap;)V + public static synthetic fun show$default (Lcom/squareup/workflow1/ui/WorkflowLayout;Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/LocalMap;ILjava/lang/Object;)V + public final fun start (Landroidx/lifecycle/Lifecycle;Lkotlinx/coroutines/flow/Flow;Landroidx/lifecycle/Lifecycle$State;Lcom/squareup/workflow1/LocalMap;)V public final fun start (Landroidx/lifecycle/Lifecycle;Lkotlinx/coroutines/flow/Flow;Lcom/squareup/workflow1/ui/ViewRegistry;)V - public final fun start (Lkotlinx/coroutines/flow/Flow;Lcom/squareup/workflow1/ui/ViewEnvironment;)V + public final fun start (Lkotlinx/coroutines/flow/Flow;Lcom/squareup/workflow1/LocalMap;)V public final fun start (Lkotlinx/coroutines/flow/Flow;Lcom/squareup/workflow1/ui/ViewRegistry;)V - public static synthetic fun start$default (Lcom/squareup/workflow1/ui/WorkflowLayout;Landroidx/lifecycle/Lifecycle;Lkotlinx/coroutines/flow/Flow;Landroidx/lifecycle/Lifecycle$State;Lcom/squareup/workflow1/ui/ViewEnvironment;ILjava/lang/Object;)V - public static synthetic fun start$default (Lcom/squareup/workflow1/ui/WorkflowLayout;Lkotlinx/coroutines/flow/Flow;Lcom/squareup/workflow1/ui/ViewEnvironment;ILjava/lang/Object;)V + public static synthetic fun start$default (Lcom/squareup/workflow1/ui/WorkflowLayout;Landroidx/lifecycle/Lifecycle;Lkotlinx/coroutines/flow/Flow;Landroidx/lifecycle/Lifecycle$State;Lcom/squareup/workflow1/LocalMap;ILjava/lang/Object;)V + public static synthetic fun start$default (Lcom/squareup/workflow1/ui/WorkflowLayout;Lkotlinx/coroutines/flow/Flow;Lcom/squareup/workflow1/LocalMap;ILjava/lang/Object;)V public final fun take (Landroidx/lifecycle/Lifecycle;Lkotlinx/coroutines/flow/Flow;Landroidx/lifecycle/Lifecycle$State;Lkotlin/coroutines/CoroutineContext;)V public static synthetic fun take$default (Lcom/squareup/workflow1/ui/WorkflowLayout;Landroidx/lifecycle/Lifecycle;Lkotlinx/coroutines/flow/Flow;Landroidx/lifecycle/Lifecycle$State;Lkotlin/coroutines/CoroutineContext;ILjava/lang/Object;)V - public final fun update (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;)V + public final fun update (Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;)V } public abstract class com/squareup/workflow1/ui/WorkflowViewState { - public abstract fun getEnvironment ()Lcom/squareup/workflow1/ui/ViewEnvironment; + public abstract fun getEnvironment ()Lcom/squareup/workflow1/LocalMap; public abstract fun getShowRendering ()Lkotlin/jvm/functions/Function2; public abstract fun getShowing ()Ljava/lang/Object; } public final class com/squareup/workflow1/ui/WorkflowViewState$New : com/squareup/workflow1/ui/WorkflowViewState { - public fun (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)V - public synthetic fun (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun component2 ()Lcom/squareup/workflow1/ui/ViewEnvironment; + public fun (Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)V + public synthetic fun (Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun component2 ()Lcom/squareup/workflow1/LocalMap; public final fun component3 ()Lkotlin/jvm/functions/Function2; public final fun component4 ()Lkotlin/jvm/functions/Function1; - public final fun copy (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)Lcom/squareup/workflow1/ui/WorkflowViewState$New; - public static synthetic fun copy$default (Lcom/squareup/workflow1/ui/WorkflowViewState$New;Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/squareup/workflow1/ui/WorkflowViewState$New; + public final fun copy (Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)Lcom/squareup/workflow1/ui/WorkflowViewState$New; + public static synthetic fun copy$default (Lcom/squareup/workflow1/ui/WorkflowViewState$New;Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/squareup/workflow1/ui/WorkflowViewState$New; public fun equals (Ljava/lang/Object;)Z - public fun getEnvironment ()Lcom/squareup/workflow1/ui/ViewEnvironment; + public fun getEnvironment ()Lcom/squareup/workflow1/LocalMap; public fun getShowRendering ()Lkotlin/jvm/functions/Function2; public synthetic fun getShowing ()Ljava/lang/Object; public final fun getStarter ()Lkotlin/jvm/functions/Function1; @@ -245,13 +245,13 @@ public final class com/squareup/workflow1/ui/WorkflowViewState$New : com/squareu } public final class com/squareup/workflow1/ui/WorkflowViewState$Started : com/squareup/workflow1/ui/WorkflowViewState { - public fun (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function2;)V - public final fun component2 ()Lcom/squareup/workflow1/ui/ViewEnvironment; + public fun (Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Lkotlin/jvm/functions/Function2;)V + public final fun component2 ()Lcom/squareup/workflow1/LocalMap; public final fun component3 ()Lkotlin/jvm/functions/Function2; - public final fun copy (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function2;)Lcom/squareup/workflow1/ui/WorkflowViewState$Started; - public static synthetic fun copy$default (Lcom/squareup/workflow1/ui/WorkflowViewState$Started;Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lcom/squareup/workflow1/ui/WorkflowViewState$Started; + public final fun copy (Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Lkotlin/jvm/functions/Function2;)Lcom/squareup/workflow1/ui/WorkflowViewState$Started; + public static synthetic fun copy$default (Lcom/squareup/workflow1/ui/WorkflowViewState$Started;Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lcom/squareup/workflow1/ui/WorkflowViewState$Started; public fun equals (Ljava/lang/Object;)Z - public fun getEnvironment ()Lcom/squareup/workflow1/ui/ViewEnvironment; + public fun getEnvironment ()Lcom/squareup/workflow1/LocalMap; public fun getShowRendering ()Lkotlin/jvm/functions/Function2; public synthetic fun getShowing ()Ljava/lang/Object; public fun hashCode ()I @@ -279,15 +279,15 @@ public final class com/squareup/workflow1/ui/WorkflowViewStub : android/view/Vie public final fun setReplaceOldViewInParent (Lkotlin/jvm/functions/Function2;)V public final fun setUpdatesVisibility (Z)V public fun setVisibility (I)V - public final fun show (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;)V - public final fun update (Ljava/lang/Object;Lcom/squareup/workflow1/ui/ViewEnvironment;)Landroid/view/View; + public final fun show (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/LocalMap;)V + public final fun update (Ljava/lang/Object;Lcom/squareup/workflow1/LocalMap;)Landroid/view/View; } public final class com/squareup/workflow1/ui/androidx/WorkflowAndroidXSupport { public static final field INSTANCE Lcom/squareup/workflow1/ui/androidx/WorkflowAndroidXSupport; public final fun lifecycleOwnerFromContext (Landroid/content/Context;)Landroidx/lifecycle/LifecycleOwner; public final fun lifecycleOwnerFromViewTreeOrContextOrNull (Landroid/view/View;)Landroidx/lifecycle/LifecycleOwner; - public final fun onBackPressedDispatcherOwner (Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/view/View;)Landroidx/activity/OnBackPressedDispatcherOwner; + public final fun onBackPressedDispatcherOwner (Lcom/squareup/workflow1/LocalMap;Landroid/view/View;)Landroidx/activity/OnBackPressedDispatcherOwner; public final fun onBackPressedDispatcherOwnerOrNull (Landroid/view/View;)Landroidx/activity/OnBackPressedDispatcherOwner; public final fun stateRegistryOwnerFromViewTreeOrContext (Landroid/view/View;)Landroidx/savedstate/SavedStateRegistryOwner; } @@ -314,14 +314,14 @@ public final class com/squareup/workflow1/ui/androidx/WorkflowSavedStateRegistry public final fun saveAndPruneChildRegistryOwner (Ljava/lang/String;)V } -public final class com/squareup/workflow1/ui/container/AlertDialogThemeResId : com/squareup/workflow1/ui/ViewEnvironmentKey { +public final class com/squareup/workflow1/ui/container/AlertDialogThemeResId : com/squareup/workflow1/LocalMapKey { public static final field INSTANCE Lcom/squareup/workflow1/ui/container/AlertDialogThemeResId; public fun getDefault ()Ljava/lang/Integer; public synthetic fun getDefault ()Ljava/lang/Object; } public final class com/squareup/workflow1/ui/container/AlertOverlayDialogFactoryKt { - public static final fun toDialogHolder (Landroid/app/AlertDialog;Lcom/squareup/workflow1/ui/ViewEnvironment;)Lcom/squareup/workflow1/ui/container/OverlayDialogHolder; + public static final fun toDialogHolder (Landroid/app/AlertDialog;Lcom/squareup/workflow1/LocalMap;)Lcom/squareup/workflow1/ui/container/OverlayDialogHolder; } public final class com/squareup/workflow1/ui/container/AndroidDialogBoundsKt { @@ -334,8 +334,8 @@ public abstract interface class com/squareup/workflow1/ui/container/AndroidOverl } public final class com/squareup/workflow1/ui/container/AsDialogHolderWithContentKt { - public static final fun asDialogHolderWithContent (Landroidx/activity/ComponentDialog;Lcom/squareup/workflow1/ui/container/ScreenOverlay;Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function1;)Lcom/squareup/workflow1/ui/container/OverlayDialogHolder; - public static synthetic fun asDialogHolderWithContent$default (Landroidx/activity/ComponentDialog;Lcom/squareup/workflow1/ui/container/ScreenOverlay;Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/squareup/workflow1/ui/container/OverlayDialogHolder; + public static final fun asDialogHolderWithContent (Landroidx/activity/ComponentDialog;Lcom/squareup/workflow1/ui/container/ScreenOverlay;Lcom/squareup/workflow1/LocalMap;Lkotlin/jvm/functions/Function1;)Lcom/squareup/workflow1/ui/container/OverlayDialogHolder; + public static synthetic fun asDialogHolderWithContent$default (Landroidx/activity/ComponentDialog;Lcom/squareup/workflow1/ui/container/ScreenOverlay;Lcom/squareup/workflow1/LocalMap;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/squareup/workflow1/ui/container/OverlayDialogHolder; public static final fun fixBackgroundAndDimming (Landroid/app/Dialog;)V } @@ -366,7 +366,7 @@ public class com/squareup/workflow1/ui/container/BackStackContainer : android/wi protected fun onRestoreInstanceState (Landroid/os/Parcelable;)V protected fun onSaveInstanceState ()Landroid/os/Parcelable; protected fun performTransition (Lcom/squareup/workflow1/ui/ScreenViewHolder;Lcom/squareup/workflow1/ui/ScreenViewHolder;Z)V - public final fun update (Lcom/squareup/workflow1/ui/container/BackStackScreen;Lcom/squareup/workflow1/ui/ViewEnvironment;)V + public final fun update (Lcom/squareup/workflow1/ui/container/BackStackScreen;Lcom/squareup/workflow1/LocalMap;)V } public final class com/squareup/workflow1/ui/container/BackStackContainer$SavedState : android/view/View$BaseSavedState { @@ -392,7 +392,7 @@ public final class com/squareup/workflow1/ui/container/LayeredDialogSessions { public final fun onDetachedFromWindow ()V public final fun onRestoreInstanceState (Lcom/squareup/workflow1/ui/container/LayeredDialogSessions$SavedState;)V public final fun onSaveInstanceState ()Lcom/squareup/workflow1/ui/container/LayeredDialogSessions$SavedState; - public final fun update (Ljava/util/List;Lcom/squareup/workflow1/ui/ViewEnvironment;Lkotlin/jvm/functions/Function1;)V + public final fun update (Ljava/util/List;Lcom/squareup/workflow1/LocalMap;Lkotlin/jvm/functions/Function1;)V } public final class com/squareup/workflow1/ui/container/LayeredDialogSessions$Companion { @@ -415,7 +415,7 @@ public final class com/squareup/workflow1/ui/container/LayeredDialogSessions$Sav public abstract interface class com/squareup/workflow1/ui/container/OverlayDialogFactory : com/squareup/workflow1/ui/ViewRegistry$Entry { public static final field Companion Lcom/squareup/workflow1/ui/container/OverlayDialogFactory$Companion; - public abstract fun buildDialog (Lcom/squareup/workflow1/ui/container/Overlay;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;)Lcom/squareup/workflow1/ui/container/OverlayDialogHolder; + public abstract fun buildDialog (Lcom/squareup/workflow1/ui/container/Overlay;Lcom/squareup/workflow1/LocalMap;Landroid/content/Context;)Lcom/squareup/workflow1/ui/container/OverlayDialogHolder; } public final class com/squareup/workflow1/ui/container/OverlayDialogFactory$Companion { @@ -423,47 +423,47 @@ public final class com/squareup/workflow1/ui/container/OverlayDialogFactory$Comp public abstract interface class com/squareup/workflow1/ui/container/OverlayDialogFactoryFinder { public static final field Companion Lcom/squareup/workflow1/ui/container/OverlayDialogFactoryFinder$Companion; - public abstract fun getDialogFactoryForRendering (Lcom/squareup/workflow1/ui/ViewEnvironment;Lcom/squareup/workflow1/ui/container/Overlay;)Lcom/squareup/workflow1/ui/container/OverlayDialogFactory; + public abstract fun getDialogFactoryForRendering (Lcom/squareup/workflow1/LocalMap;Lcom/squareup/workflow1/ui/container/Overlay;)Lcom/squareup/workflow1/ui/container/OverlayDialogFactory; } -public final class com/squareup/workflow1/ui/container/OverlayDialogFactoryFinder$Companion : com/squareup/workflow1/ui/ViewEnvironmentKey { +public final class com/squareup/workflow1/ui/container/OverlayDialogFactoryFinder$Companion : com/squareup/workflow1/LocalMapKey { public fun getDefault ()Lcom/squareup/workflow1/ui/container/OverlayDialogFactoryFinder; public synthetic fun getDefault ()Ljava/lang/Object; } public final class com/squareup/workflow1/ui/container/OverlayDialogFactoryFinder$DefaultImpls { - public static fun getDialogFactoryForRendering (Lcom/squareup/workflow1/ui/container/OverlayDialogFactoryFinder;Lcom/squareup/workflow1/ui/ViewEnvironment;Lcom/squareup/workflow1/ui/container/Overlay;)Lcom/squareup/workflow1/ui/container/OverlayDialogFactory; + public static fun getDialogFactoryForRendering (Lcom/squareup/workflow1/ui/container/OverlayDialogFactoryFinder;Lcom/squareup/workflow1/LocalMap;Lcom/squareup/workflow1/ui/container/Overlay;)Lcom/squareup/workflow1/ui/container/OverlayDialogFactory; } public final class com/squareup/workflow1/ui/container/OverlayDialogFactoryKt { - public static final fun toDialogFactory (Lcom/squareup/workflow1/ui/container/Overlay;Lcom/squareup/workflow1/ui/ViewEnvironment;)Lcom/squareup/workflow1/ui/container/OverlayDialogFactory; + public static final fun toDialogFactory (Lcom/squareup/workflow1/ui/container/Overlay;Lcom/squareup/workflow1/LocalMap;)Lcom/squareup/workflow1/ui/container/OverlayDialogFactory; } public abstract interface class com/squareup/workflow1/ui/container/OverlayDialogHolder { public static final field Companion Lcom/squareup/workflow1/ui/container/OverlayDialogHolder$Companion; public abstract fun getDialog ()Landroid/app/Dialog; - public abstract fun getEnvironment ()Lcom/squareup/workflow1/ui/ViewEnvironment; + public abstract fun getEnvironment ()Lcom/squareup/workflow1/LocalMap; public abstract fun getOnBackPressed ()Lkotlin/jvm/functions/Function0; public abstract fun getOnUpdateBounds ()Lkotlin/jvm/functions/Function1; public abstract fun getRunner ()Lkotlin/jvm/functions/Function2; } public final class com/squareup/workflow1/ui/container/OverlayDialogHolder$Companion { - public final fun invoke (Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/app/Dialog;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function2;)Lcom/squareup/workflow1/ui/container/OverlayDialogHolder; - public static synthetic fun invoke$default (Lcom/squareup/workflow1/ui/container/OverlayDialogHolder$Companion;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/app/Dialog;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lcom/squareup/workflow1/ui/container/OverlayDialogHolder; + public final fun invoke (Lcom/squareup/workflow1/LocalMap;Landroid/app/Dialog;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function2;)Lcom/squareup/workflow1/ui/container/OverlayDialogHolder; + public static synthetic fun invoke$default (Lcom/squareup/workflow1/ui/container/OverlayDialogHolder$Companion;Lcom/squareup/workflow1/LocalMap;Landroid/app/Dialog;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lcom/squareup/workflow1/ui/container/OverlayDialogHolder; } public final class com/squareup/workflow1/ui/container/OverlayDialogHolderKt { public static final fun canShow (Lcom/squareup/workflow1/ui/container/OverlayDialogHolder;Lcom/squareup/workflow1/ui/container/Overlay;)Z public static final fun getShowing (Lcom/squareup/workflow1/ui/container/OverlayDialogHolder;)Lcom/squareup/workflow1/ui/container/Overlay; - public static final fun show (Lcom/squareup/workflow1/ui/container/OverlayDialogHolder;Lcom/squareup/workflow1/ui/container/Overlay;Lcom/squareup/workflow1/ui/ViewEnvironment;)V + public static final fun show (Lcom/squareup/workflow1/ui/container/OverlayDialogHolder;Lcom/squareup/workflow1/ui/container/Overlay;Lcom/squareup/workflow1/LocalMap;)V } public class com/squareup/workflow1/ui/container/ScreenOverlayDialogFactory : com/squareup/workflow1/ui/container/OverlayDialogFactory { public fun (Lkotlin/reflect/KClass;)V - public synthetic fun buildDialog (Lcom/squareup/workflow1/ui/container/Overlay;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;)Lcom/squareup/workflow1/ui/container/OverlayDialogHolder; - public final fun buildDialog (Lcom/squareup/workflow1/ui/container/ScreenOverlay;Lcom/squareup/workflow1/ui/ViewEnvironment;Landroid/content/Context;)Lcom/squareup/workflow1/ui/container/OverlayDialogHolder; - public fun buildDialogWithContent (Lcom/squareup/workflow1/ui/container/ScreenOverlay;Lcom/squareup/workflow1/ui/ViewEnvironment;Lcom/squareup/workflow1/ui/ScreenViewHolder;)Lcom/squareup/workflow1/ui/container/OverlayDialogHolder; + public synthetic fun buildDialog (Lcom/squareup/workflow1/ui/container/Overlay;Lcom/squareup/workflow1/LocalMap;Landroid/content/Context;)Lcom/squareup/workflow1/ui/container/OverlayDialogHolder; + public final fun buildDialog (Lcom/squareup/workflow1/ui/container/ScreenOverlay;Lcom/squareup/workflow1/LocalMap;Landroid/content/Context;)Lcom/squareup/workflow1/ui/container/OverlayDialogHolder; + public fun buildDialogWithContent (Lcom/squareup/workflow1/ui/container/ScreenOverlay;Lcom/squareup/workflow1/LocalMap;Lcom/squareup/workflow1/ui/ScreenViewHolder;)Lcom/squareup/workflow1/ui/container/OverlayDialogHolder; public fun getType ()Lkotlin/reflect/KClass; } diff --git a/workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/WorkflowLayout.kt b/workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/WorkflowLayout.kt index 7ed280da40..b429587ef7 100644 --- a/workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/WorkflowLayout.kt +++ b/workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/WorkflowLayout.kt @@ -182,7 +182,7 @@ public class WorkflowLayout( start( lifecycle = lifecycle, renderings = renderings, - environment = ViewEnvironment(mapOf(ViewRegistry to registry)) + environment = EmptyViewEnvironment + registry ) } @@ -221,7 +221,7 @@ public class WorkflowLayout( registry: ViewRegistry ) { @Suppress("DEPRECATION") - start(renderings, ViewEnvironment(mapOf(ViewRegistry to registry))) + start(renderings, EmptyViewEnvironment + registry) } override fun onSaveInstanceState(): Parcelable { diff --git a/workflow-ui/core-common/api/core-common.api b/workflow-ui/core-common/api/core-common.api index e8d392eb00..cde600c375 100644 --- a/workflow-ui/core-common/api/core-common.api +++ b/workflow-ui/core-common/api/core-common.api @@ -80,31 +80,8 @@ public final class com/squareup/workflow1/ui/TextControllerKt { public static synthetic fun TextController$default (Ljava/lang/String;ILjava/lang/Object;)Lcom/squareup/workflow1/ui/TextController; } -public final class com/squareup/workflow1/ui/ViewEnvironment { - public static final field Companion Lcom/squareup/workflow1/ui/ViewEnvironment$Companion; - public fun ()V - public fun (Ljava/util/Map;)V - public synthetic fun (Ljava/util/Map;ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public fun equals (Ljava/lang/Object;)Z - public final fun get (Lcom/squareup/workflow1/ui/ViewEnvironmentKey;)Ljava/lang/Object; - public final fun getMap ()Ljava/util/Map; - public fun hashCode ()I - public final fun plus (Lcom/squareup/workflow1/ui/ViewEnvironment;)Lcom/squareup/workflow1/ui/ViewEnvironment; - public final fun plus (Lkotlin/Pair;)Lcom/squareup/workflow1/ui/ViewEnvironment; - public fun toString ()Ljava/lang/String; -} - -public final class com/squareup/workflow1/ui/ViewEnvironment$Companion { - public final fun getEMPTY ()Lcom/squareup/workflow1/ui/ViewEnvironment; -} - -public abstract class com/squareup/workflow1/ui/ViewEnvironmentKey { - public fun ()V - public fun (Lkotlin/reflect/KClass;)V - public fun combine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public final fun equals (Ljava/lang/Object;)Z - public abstract fun getDefault ()Ljava/lang/Object; - public final fun hashCode ()I +public final class com/squareup/workflow1/ui/ViewEnvironmentKt { + public static final fun getEmptyViewEnvironment ()Lcom/squareup/workflow1/LocalMap; } public abstract interface class com/squareup/workflow1/ui/ViewRegistry { @@ -113,7 +90,7 @@ public abstract interface class com/squareup/workflow1/ui/ViewRegistry { public abstract fun getKeys ()Ljava/util/Set; } -public final class com/squareup/workflow1/ui/ViewRegistry$Companion : com/squareup/workflow1/ui/ViewEnvironmentKey { +public final class com/squareup/workflow1/ui/ViewRegistry$Companion : com/squareup/workflow1/LocalMapKey { public fun combine (Lcom/squareup/workflow1/ui/ViewRegistry;Lcom/squareup/workflow1/ui/ViewRegistry;)Lcom/squareup/workflow1/ui/ViewRegistry; public synthetic fun combine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public fun getDefault ()Lcom/squareup/workflow1/ui/ViewRegistry; @@ -128,7 +105,7 @@ public final class com/squareup/workflow1/ui/ViewRegistryKt { public static final fun ViewRegistry ()Lcom/squareup/workflow1/ui/ViewRegistry; public static final fun ViewRegistry ([Lcom/squareup/workflow1/ui/ViewRegistry$Entry;)Lcom/squareup/workflow1/ui/ViewRegistry; public static final fun merge (Lcom/squareup/workflow1/ui/ViewRegistry;Lcom/squareup/workflow1/ui/ViewRegistry;)Lcom/squareup/workflow1/ui/ViewRegistry; - public static final fun plus (Lcom/squareup/workflow1/ui/ViewEnvironment;Lcom/squareup/workflow1/ui/ViewRegistry;)Lcom/squareup/workflow1/ui/ViewEnvironment; + public static final fun plus (Lcom/squareup/workflow1/LocalMap;Lcom/squareup/workflow1/ui/ViewRegistry;)Lcom/squareup/workflow1/LocalMap; public static final fun plus (Lcom/squareup/workflow1/ui/ViewRegistry;Lcom/squareup/workflow1/ui/ViewRegistry$Entry;)Lcom/squareup/workflow1/ui/ViewRegistry; public static final fun plus (Lcom/squareup/workflow1/ui/ViewRegistry;Lcom/squareup/workflow1/ui/ViewRegistry;)Lcom/squareup/workflow1/ui/ViewRegistry; } @@ -203,13 +180,13 @@ public final class com/squareup/workflow1/ui/container/BackStackConfig : java/la public static fun values ()[Lcom/squareup/workflow1/ui/container/BackStackConfig; } -public final class com/squareup/workflow1/ui/container/BackStackConfig$Companion : com/squareup/workflow1/ui/ViewEnvironmentKey { +public final class com/squareup/workflow1/ui/container/BackStackConfig$Companion : com/squareup/workflow1/LocalMapKey { public fun getDefault ()Lcom/squareup/workflow1/ui/container/BackStackConfig; public synthetic fun getDefault ()Ljava/lang/Object; } public final class com/squareup/workflow1/ui/container/BackStackConfigKt { - public static final fun plus (Lcom/squareup/workflow1/ui/ViewEnvironment;Lcom/squareup/workflow1/ui/container/BackStackConfig;)Lcom/squareup/workflow1/ui/ViewEnvironment; + public static final fun plus (Lcom/squareup/workflow1/LocalMap;Lcom/squareup/workflow1/ui/container/BackStackConfig;)Lcom/squareup/workflow1/LocalMap; } public final class com/squareup/workflow1/ui/container/BackStackScreen : com/squareup/workflow1/ui/Container, com/squareup/workflow1/ui/Screen { @@ -248,13 +225,13 @@ public final class com/squareup/workflow1/ui/container/BodyAndOverlaysScreen : c } public final class com/squareup/workflow1/ui/container/EnvironmentScreen : com/squareup/workflow1/ui/Screen, com/squareup/workflow1/ui/Wrapper { - public fun (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;)V - public synthetic fun (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/LocalMap;)V + public synthetic fun (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/LocalMap;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun asSequence ()Lkotlin/sequences/Sequence; public fun getCompatibilityKey ()Ljava/lang/String; public fun getContent ()Lcom/squareup/workflow1/ui/Screen; public synthetic fun getContent ()Ljava/lang/Object; - public final fun getEnvironment ()Lcom/squareup/workflow1/ui/ViewEnvironment; + public final fun getEnvironment ()Lcom/squareup/workflow1/LocalMap; public final fun getWrapped ()Lcom/squareup/workflow1/ui/Screen; public synthetic fun map (Lkotlin/jvm/functions/Function1;)Lcom/squareup/workflow1/ui/Container; public synthetic fun map (Lkotlin/jvm/functions/Function1;)Lcom/squareup/workflow1/ui/Wrapper; @@ -262,8 +239,8 @@ public final class com/squareup/workflow1/ui/container/EnvironmentScreen : com/s } public final class com/squareup/workflow1/ui/container/EnvironmentScreenKt { - public static final fun withEnvironment (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;)Lcom/squareup/workflow1/ui/container/EnvironmentScreen; - public static synthetic fun withEnvironment$default (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;ILjava/lang/Object;)Lcom/squareup/workflow1/ui/container/EnvironmentScreen; + public static final fun withEnvironment (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/LocalMap;)Lcom/squareup/workflow1/ui/container/EnvironmentScreen; + public static synthetic fun withEnvironment$default (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/LocalMap;ILjava/lang/Object;)Lcom/squareup/workflow1/ui/container/EnvironmentScreen; public static final fun withRegistry (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewRegistry;)Lcom/squareup/workflow1/ui/container/EnvironmentScreen; } diff --git a/workflow-ui/core-common/build.gradle.kts b/workflow-ui/core-common/build.gradle.kts index 811df65fb6..f05c32186a 100644 --- a/workflow-ui/core-common/build.gradle.kts +++ b/workflow-ui/core-common/build.gradle.kts @@ -8,6 +8,8 @@ dependencies { api(libs.kotlinx.coroutines.core) api(libs.squareup.okio) + api(project(":workflow-core")) + testImplementation(libs.junit) testImplementation(libs.kotlin.test.core) testImplementation(libs.kotlin.test.jdk) diff --git a/workflow-ui/core-common/src/main/java/com/squareup/workflow1/ui/ViewEnvironment.kt b/workflow-ui/core-common/src/main/java/com/squareup/workflow1/ui/ViewEnvironment.kt index 3508f820dd..54c6f9a639 100644 --- a/workflow-ui/core-common/src/main/java/com/squareup/workflow1/ui/ViewEnvironment.kt +++ b/workflow-ui/core-common/src/main/java/com/squareup/workflow1/ui/ViewEnvironment.kt @@ -1,98 +1,22 @@ package com.squareup.workflow1.ui -import kotlin.reflect.KClass +import com.squareup.workflow1.LocalMap +import com.squareup.workflow1.LocalMapKey + +public typealias ViewEnvironmentKey = LocalMapKey /** * Immutable map of values that a parent view can pass down to * its children. Allows containers to give descendants information about * the context in which they're drawing. * + * @see LocalMap for implementation + * * Calling [Screen.withEnvironment][com.squareup.workflow1.ui.container.withEnvironment] * on a [Screen] is the easiest way to customize its environment before rendering it. */ @WorkflowUiExperimentalApi -public class ViewEnvironment -@Deprecated( - "To eliminate runtime errors this constructor will become private. " + - "Use ViewEnvironment.EMPTY and ViewEnvironment.plus" -) -constructor( - public val map: Map, Any> = emptyMap() -) { - public operator fun get(key: ViewEnvironmentKey): T = getOrNull(key) ?: key.default - - public operator fun plus(pair: Pair, T>): ViewEnvironment { - val (newKey, newValue) = pair - val newPair = getOrNull(newKey) - ?.let { oldValue -> newKey to newKey.combine(oldValue, newValue) } - ?: pair - @Suppress("DEPRECATION") - return ViewEnvironment(map + newPair) - } - - @Suppress("DEPRECATION") - public operator fun plus(other: ViewEnvironment): ViewEnvironment { - if (this == other) return this - if (other.map.isEmpty()) return this - if (map.isEmpty()) return other - val newMap = map.toMutableMap() - other.map.entries.forEach { (key, value) -> - @Suppress("UNCHECKED_CAST") - newMap[key] = getOrNull(key as ViewEnvironmentKey) - ?.let { oldValue -> key.combine(oldValue, value) } - ?: value - } - return ViewEnvironment(newMap) - } - - override fun toString(): String = "ViewEnvironment($map)" - - override fun equals(other: Any?): Boolean = - (other as? ViewEnvironment)?.let { it.map == map } ?: false - - override fun hashCode(): Int = map.hashCode() - - @Suppress("UNCHECKED_CAST") - private fun getOrNull(key: ViewEnvironmentKey): T? = map[key] as? T +public typealias ViewEnvironment = LocalMap - public companion object { - @Suppress("DEPRECATION") - public val EMPTY: ViewEnvironment = ViewEnvironment() - } -} - -/** - * Defines a value type [T] that can be provided by a [ViewEnvironment] map, - * and specifies its [default] value. - * - * It is hard to imagine a useful implementation of this that is not a Kotlin `object`. - * Preferred use is to have the `companion object` of [T] extend this class. See - * [BackStackConfig.Companion][com.squareup.workflow1.ui.container.BackStackConfig.Companion] - * for an example. - */ @WorkflowUiExperimentalApi -public abstract class ViewEnvironmentKey() { - @Deprecated("Use no args constructor", ReplaceWith("ViewEnvironmentKey()")) - public constructor(@Suppress("UNUSED_PARAMETER") type: KClass) : this() - - /** - * Defines the default value for this key. It is a grievous error for this value to be - * dynamic in any way. - */ - public abstract val default: T - - /** - * Applied from [ViewEnvironment.plus] when the receiving environment already contains - * a value for this key. The default implementation replaces [left] with [right]. - */ - public open fun combine( - left: T, - right: T - ): T = right - - final override fun equals(other: Any?): Boolean { - return this === other || (other != null && this::class == other::class) - } - - final override fun hashCode(): Int = this::class.hashCode() -} +public val EmptyViewEnvironment: ViewEnvironment = LocalMap.Companion.EMPTY diff --git a/workflow-ui/core-common/src/test/java/com/squareup/workflow1/ui/ViewEnvironmentTest.kt b/workflow-ui/core-common/src/test/java/com/squareup/workflow1/ui/ViewEnvironmentTest.kt index 6f8186445e..3169d523ea 100644 --- a/workflow-ui/core-common/src/test/java/com/squareup/workflow1/ui/ViewEnvironmentTest.kt +++ b/workflow-ui/core-common/src/test/java/com/squareup/workflow1/ui/ViewEnvironmentTest.kt @@ -1,7 +1,6 @@ package com.squareup.workflow1.ui import com.google.common.truth.Truth.assertThat -import com.squareup.workflow1.ui.ViewEnvironment.Companion.EMPTY import org.junit.Test @OptIn(WorkflowUiExperimentalApi::class) @@ -24,11 +23,11 @@ internal class ViewEnvironmentTest { } @Test fun defaults() { - assertThat(EMPTY[DataHint]).isEqualTo(DataHint()) + assertThat(EmptyViewEnvironment[DataHint]).isEqualTo(DataHint()) } @Test fun put() { - val environment = EMPTY + + val environment = EmptyViewEnvironment + (StringHint to "fnord") + (DataHint to DataHint(42, "foo")) @@ -37,11 +36,11 @@ internal class ViewEnvironmentTest { } @Test fun `map equality`() { - val env1 = EMPTY + + val env1 = EmptyViewEnvironment + (StringHint to "fnord") + (DataHint to DataHint(42, "foo")) - val env2 = EMPTY + + val env2 = EmptyViewEnvironment + (StringHint to "fnord") + (DataHint to DataHint(42, "foo")) @@ -49,11 +48,11 @@ internal class ViewEnvironmentTest { } @Test fun `map inequality`() { - val env1 = EMPTY + + val env1 = EmptyViewEnvironment + (StringHint to "fnord") + (DataHint to DataHint(42, "foo")) - val env2 = EMPTY + + val env2 = EmptyViewEnvironment + (StringHint to "fnord") + (DataHint to DataHint(43, "foo")) @@ -69,7 +68,7 @@ internal class ViewEnvironmentTest { } @Test fun override() { - val environment = EMPTY + + val environment = EmptyViewEnvironment + (StringHint to "able") + (StringHint to "baker") @@ -77,7 +76,7 @@ internal class ViewEnvironmentTest { } @Test fun `keys of the same type`() { - val environment = EMPTY + + val environment = EmptyViewEnvironment + (StringHint to "able") + (OtherStringHint to "baker") @@ -86,17 +85,17 @@ internal class ViewEnvironmentTest { } @Test fun `preserve this when merging empty`() { - val environment = EMPTY + (StringHint to "able") - assertThat(environment + EMPTY).isSameInstanceAs(environment) + val environment = EmptyViewEnvironment + (StringHint to "able") + assertThat(environment + EmptyViewEnvironment).isSameInstanceAs(environment) } @Test fun `preserve other when merging to empty`() { - val environment = EMPTY + (StringHint to "able") - assertThat(EMPTY + environment).isSameInstanceAs(environment) + val environment = EmptyViewEnvironment + (StringHint to "able") + assertThat(EmptyViewEnvironment + environment).isSameInstanceAs(environment) } @Test fun `self plus self is self`() { - val environment = EMPTY + (StringHint to "able") + val environment = EmptyViewEnvironment + (StringHint to "able") assertThat(environment + environment).isSameInstanceAs(environment) } @@ -113,8 +112,8 @@ internal class ViewEnvironmentTest { } } - val left = EMPTY + (combiningHint to "able") - val right = EMPTY + (combiningHint to "baker") + val left = EmptyViewEnvironment + (combiningHint to "able") + val right = EmptyViewEnvironment + (combiningHint to "baker") assertThat((left + right)[combiningHint]).isEqualTo("able-baker") } } diff --git a/workflow-ui/internal-testing-android/api/internal-testing-android.api b/workflow-ui/internal-testing-android/api/internal-testing-android.api index 31b13f38e9..2368691eac 100644 --- a/workflow-ui/internal-testing-android/api/internal-testing-android.api +++ b/workflow-ui/internal-testing-android/api/internal-testing-android.api @@ -73,32 +73,32 @@ public final class com/squareup/workflow1/ui/internal/test/IdlingDispatcherRule } public class com/squareup/workflow1/ui/internal/test/LegacyWorkflowUiTestActivity : androidx/appcompat/app/AppCompatActivity { - public field viewEnvironment Lcom/squareup/workflow1/ui/ViewEnvironment; + public field viewEnvironment Lcom/squareup/workflow1/LocalMap; public fun ()V public final fun getCustomNonConfigurationData ()Ljava/util/Map; public final fun getRestoreRenderingAfterConfigChange ()Z public final fun getRootRenderedView ()Landroid/view/View; - public final fun getViewEnvironment ()Lcom/squareup/workflow1/ui/ViewEnvironment; + public final fun getViewEnvironment ()Lcom/squareup/workflow1/LocalMap; protected fun onCreate (Landroid/os/Bundle;)V public final fun onRetainCustomNonConfigurationInstance ()Ljava/lang/Object; public final fun recreateViewsOnNextRendering ()V public final fun setRendering (Ljava/lang/Object;)Landroid/view/View; public final fun setRestoreRenderingAfterConfigChange (Z)V - public final fun setViewEnvironment (Lcom/squareup/workflow1/ui/ViewEnvironment;)V + public final fun setViewEnvironment (Lcom/squareup/workflow1/LocalMap;)V } public class com/squareup/workflow1/ui/internal/test/WorkflowUiTestActivity : androidx/appcompat/app/AppCompatActivity { - public field viewEnvironment Lcom/squareup/workflow1/ui/ViewEnvironment; + public field viewEnvironment Lcom/squareup/workflow1/LocalMap; public fun ()V public final fun getCustomNonConfigurationData ()Ljava/util/Map; public final fun getRestoreRenderingAfterConfigChange ()Z public final fun getRootRenderedView ()Landroid/view/View; - public final fun getViewEnvironment ()Lcom/squareup/workflow1/ui/ViewEnvironment; + public final fun getViewEnvironment ()Lcom/squareup/workflow1/LocalMap; protected fun onCreate (Landroid/os/Bundle;)V public final fun onRetainCustomNonConfigurationInstance ()Ljava/lang/Object; public final fun recreateViewsOnNextRendering ()V public final fun setRendering (Lcom/squareup/workflow1/ui/Screen;)Landroid/view/View; public final fun setRestoreRenderingAfterConfigChange (Z)V - public final fun setViewEnvironment (Lcom/squareup/workflow1/ui/ViewEnvironment;)V + public final fun setViewEnvironment (Lcom/squareup/workflow1/LocalMap;)V }