5
5
package com.squareup.workflow1
6
6
7
7
import com.squareup.workflow1.RuntimeConfigOptions.STABLE_EVENT_HANDLERS
8
- import com.squareup.workflow1.StatefulWorkflow.RenderContext
9
- import com.squareup.workflow1.WorkflowAction.Companion.toString
10
8
import kotlinx.coroutines.CoroutineScope
11
9
import kotlin.jvm.JvmMultifileClass
12
10
import kotlin.jvm.JvmName
@@ -75,7 +73,7 @@ public abstract class StatefulWorkflow<
75
73
out RenderingT
76
74
> : Workflow <PropsT , OutputT , RenderingT >, IdCacheable {
77
75
78
- public inner class RenderContext internal constructor(
76
+ public class RenderContext < PropsT , StateT , OutputT > internal constructor(
79
77
baseContext : BaseRenderContext <PropsT , StateT , OutputT >
80
78
) : BaseRenderContext<PropsT, StateT, OutputT> by baseContext {
81
79
@PublishedApi
@@ -748,15 +746,6 @@ public abstract class StatefulWorkflow<
748
746
? : onFailedCast(name, CurrentStateT ::class , state)
749
747
}
750
748
751
- @PublishedApi
752
- internal fun defaultOnFailedCast (
753
- name : String ,
754
- expectedType : KClass <* >,
755
- state : StateT
756
- ) {
757
- println (" $name expected state of type ${expectedType.simpleName} , got $state " )
758
- }
759
-
760
749
/* *
761
750
* Called from [RenderContext.renderChild] when the state machine is first started, to get the
762
751
* initial state.
@@ -829,7 +818,7 @@ public abstract class StatefulWorkflow<
829
818
public abstract fun render (
830
819
renderProps : PropsT ,
831
820
renderState : StateT ,
832
- context : RenderContext
821
+ context : RenderContext < PropsT , StateT , OutputT >
833
822
): RenderingT
834
823
835
824
/* *
@@ -861,6 +850,18 @@ public abstract class StatefulWorkflow<
861
850
*/
862
851
final override fun asStatefulWorkflow (): StatefulWorkflow <PropsT , StateT , OutputT , RenderingT > =
863
852
this
853
+
854
+ companion object {
855
+
856
+ @PublishedApi
857
+ internal fun <StateT > defaultOnFailedCast (
858
+ name : String ,
859
+ expectedType : KClass <* >,
860
+ state : StateT
861
+ ) {
862
+ println (" $name expected state of type ${expectedType.simpleName} , got $state " )
863
+ }
864
+ }
864
865
}
865
866
866
867
/* *
@@ -870,21 +871,16 @@ public abstract class StatefulWorkflow<
870
871
public fun <PropsT , StateT , OutputT , RenderingT > RenderContext (
871
872
baseContext : BaseRenderContext <PropsT , StateT , OutputT >,
872
873
workflow : StatefulWorkflow <PropsT , StateT , OutputT , RenderingT >
873
- ): StatefulWorkflow <PropsT , StateT , OutputT , RenderingT >. RenderContext =
874
- (baseContext as ? StatefulWorkflow <PropsT , StateT , OutputT , RenderingT >. RenderContext )
875
- ? : workflow .RenderContext (baseContext)
874
+ ): StatefulWorkflow . RenderContext <PropsT , StateT , OutputT > =
875
+ (baseContext as ? StatefulWorkflow . RenderContext <PropsT , StateT , OutputT > )
876
+ ? : StatefulWorkflow .RenderContext < PropsT , StateT , OutputT > (baseContext)
876
877
877
878
/* *
878
879
* Returns a stateful [Workflow] implemented via the given functions.
879
880
*/
880
881
public inline fun <PropsT , StateT , OutputT , RenderingT > Workflow.Companion.stateful (
881
882
crossinline initialState : (PropsT , Snapshot ? ) -> StateT ,
882
- crossinline render : StatefulWorkflow <
883
- PropsT ,
884
- StateT ,
885
- OutputT ,
886
- *
887
- >.RenderContext .(
883
+ crossinline render : StatefulWorkflow .RenderContext <PropsT , StateT , OutputT >.(
888
884
props: PropsT ,
889
885
state: StateT
890
886
) -> RenderingT ,
@@ -910,7 +906,7 @@ public inline fun <PropsT, StateT, OutputT, RenderingT> Workflow.Companion.state
910
906
override fun render (
911
907
renderProps : PropsT ,
912
908
renderState : StateT ,
913
- context : RenderContext
909
+ context : RenderContext < PropsT , StateT , OutputT >
914
910
): RenderingT = render(context, renderProps, renderState)
915
911
916
912
override fun snapshotState (state : StateT ) = snapshot(state)
@@ -921,12 +917,7 @@ public inline fun <PropsT, StateT, OutputT, RenderingT> Workflow.Companion.state
921
917
*/
922
918
public inline fun <StateT , OutputT , RenderingT > Workflow.Companion.stateful (
923
919
crossinline initialState : (Snapshot ? ) -> StateT ,
924
- crossinline render : StatefulWorkflow <
925
- Unit ,
926
- StateT ,
927
- OutputT ,
928
- *
929
- >.RenderContext .(state: StateT ) -> RenderingT ,
920
+ crossinline render : StatefulWorkflow .RenderContext <Unit , StateT , OutputT >.(state: StateT ) -> RenderingT ,
930
921
crossinline snapshot : (StateT ) -> Snapshot ?
931
922
): StatefulWorkflow <Unit , StateT , OutputT , RenderingT > = stateful(
932
923
{ _, initialSnapshot -> initialState(initialSnapshot) },
@@ -941,7 +932,7 @@ public inline fun <StateT, OutputT, RenderingT> Workflow.Companion.stateful(
941
932
*/
942
933
public inline fun <PropsT , StateT , OutputT , RenderingT > Workflow.Companion.stateful (
943
934
crossinline initialState : (PropsT ) -> StateT ,
944
- crossinline render : StatefulWorkflow <PropsT , StateT , OutputT , * >. RenderContext .(
935
+ crossinline render : StatefulWorkflow . RenderContext <PropsT , StateT , OutputT > .(
945
936
props: PropsT ,
946
937
state: StateT
947
938
) -> RenderingT ,
@@ -964,12 +955,9 @@ public inline fun <PropsT, StateT, OutputT, RenderingT> Workflow.Companion.state
964
955
*/
965
956
public inline fun <StateT , OutputT , RenderingT > Workflow.Companion.stateful (
966
957
initialState : StateT ,
967
- crossinline render : StatefulWorkflow <
968
- Unit ,
958
+ crossinline render : StatefulWorkflow .RenderContext <Unit ,
969
959
StateT ,
970
- OutputT ,
971
- *
972
- >.RenderContext .(state: StateT ) -> RenderingT
960
+ OutputT >.(state: StateT ) -> RenderingT
973
961
): StatefulWorkflow <Unit , StateT , OutputT , RenderingT > = stateful(
974
962
{ initialState },
975
963
{ _, state -> render(state) }
0 commit comments