Skip to content

Update templates #362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions fileTemplates/Layout Runner (ViewBinding).kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#set( $LayoutRunnerName = "${NAME}LayoutRunner" )
#set( $ViewBindingName = "YourViewBinding" )
#set( $RenderingName = "YourRendering" )
## Unlike the Workflow Templates, we never generate inner classes for view bindings
## or rendering types. i.e. they are never "optional"
package ${PACKAGE_NAME}

import com.squareup.workflow1.ui.LayoutRunner
Expand All @@ -10,20 +9,19 @@ import com.squareup.workflow1.ui.ViewFactory
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi

#parse("File Header.java")
// TODO Change "YourViewBinding" and "YourRendering" to your actual types.
@OptIn(WorkflowUiExperimentalApi::class)
class $LayoutRunnerName(
private val binding: ${ViewBindingName}
) : LayoutRunner<${RenderingName}> {
class $Name(
private val binding: $VIEW_BINDING_TYPE
) : LayoutRunner<$RENDERING_TYPE> {

override fun showRendering(
rendering: ${RenderingName},
rendering: $RENDERING_TYPE,
viewEnvironment: ViewEnvironment
) {
TODO("Update ViewBinding from rendering")
}

companion object : ViewFactory<${RenderingName}> by bind(
${ViewBindingName}::inflate, ::$LayoutRunnerName
companion object : ViewFactory<$RENDERING_TYPE> by bind(
$VIEW_BINDING_TYPE::inflate, ::$NAME
)
}
86 changes: 69 additions & 17 deletions fileTemplates/Stateful Workflow.kt
Original file line number Diff line number Diff line change
@@ -1,35 +1,87 @@
#set( $WorkflowName = "${NAME}Workflow" )
package ${PACKAGE_NAME}
#set ($prefix = $NAME.replace('Workflow', '') )
## build props string
#if( $PROPS_TYPE_OPTIONAL == '')
#set ($props_type = $prefix + "Props")
#else
#set ($props_type = $PROPS_TYPE_OPTIONAL)
#end
## build state string
#if( $STATE_TYPE_OPTIONAL == '')
#set ($state_type = $prefix + "State")
#else
#set ($state_type = $STATE_TYPE_OPTIONAL)
#end
## build output string
#if( $OUTPUT_TYPE_OPTIONAL == '')
#set ($output_type = $prefix + "Output")
#else
#set ($output_type = $OUTPUT_TYPE_OPTIONAL)
#end
## build rendering string
#if( $RENDERING_TYPE_OPTIONAL == '')
#set ($rendering_type = $prefix + "Rendering")
#else
#set ($rendering_type = $RENDERING_TYPE_OPTIONAL)
#end
package $PACKAGE_NAME

import com.squareup.workflow1.Snapshot
import com.squareup.workflow1.StatefulWorkflow
import ${PACKAGE_NAME}.${WorkflowName}.Output
import ${PACKAGE_NAME}.${WorkflowName}.Props
import ${PACKAGE_NAME}.${WorkflowName}.Rendering
import ${PACKAGE_NAME}.${WorkflowName}.State

#if( $PROPS_TYPE_OPTIONAL == '') ## import if we create below
import $PACKAGE_NAME.$NAME.$props_type
#end
#if( $STATE_TYPE_OPTIONAL == '') ## import if we create below
import $PACKAGE_NAME.$NAME.$state_type
#end
#if( $OUTPUT_TYPE_OPTIONAL == '') ## import if we create below
import $PACKAGE_NAME.$NAME.$output_type
#end
#if( $RENDERING_TYPE_OPTIONAL == '') ## import if we create below
import $PACKAGE_NAME.$NAME.$rendering_type
#end

#parse("File Header.java")
class ${WorkflowName} : StatefulWorkflow<Props, State, Output, Rendering>() {
object $NAME : StatefulWorkflow<$props_type, $state_type, $output_type, $rendering_type>() {

data class Props
data class State
data class Output
data class Rendering
Comment on lines -14 to -17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the part where it gets trickier as suggesting this pattern of internal data classes is a goal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how complex you want it to get, but there could be an option to leave the template blank for at type and then these would be generated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool. Didn't know about the internal pattern. I'll experiment with an if --> auto generate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok @steve-the-edwards I think I have it working. If you leave an "optional" field blank then it will auto generate inner class (and import)

#if( $PROPS_TYPE_OPTIONAL == '') ## create if not supplied
data class $props_type(
// TODO add args
)
#end

#if( $STATE_TYPE_OPTIONAL == '') ## create if not supplied
data class $state_type(
// TODO add args
)
#end

#if( $OUTPUT_TYPE_OPTIONAL == '') ## create if not supplied
data class $output_type(
// TODO add args
)
#end

#if( $RENDERING_TYPE_OPTIONAL == '') ## create if not supplied
data class $rendering_type(
// TODO add args
)
#end

override fun initialState(
props: Props,
props: $props_type,
snapshot: Snapshot?
): State = TODO("Initialize state")
): $state_type = TODO("Initialize state")

override fun render(
renderProps: Props,
renderState: State,
props: $props_type,
state: $state_type,
context: RenderContext
): Rendering {
): $rendering_type {
TODO("Render")
}

override fun snapshotState(state: State): Snapshot? = Snapshot.write {
override fun snapshotState(state: $state_type): Snapshot? = Snapshot.write {
TODO("Save state")
}
}
61 changes: 50 additions & 11 deletions fileTemplates/Stateless Workflow.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,61 @@
#set( $WorkflowName = "${NAME}Workflow" )
package ${PACKAGE_NAME}
#set ($prefix = $NAME.replace('Workflow', '') )
## build props string
#if( $PROPS_TYPE_OPTIONAL == '')
#set ($props_type = $prefix + "Props")
#else
#set ($props_type = $PROPS_TYPE_OPTIONAL)
#end
## build output string
#if( $OUTPUT_TYPE_OPTIONAL == '')
#set ($output_type = $prefix + "Output")
#else
#set ($output_type = $OUTPUT_TYPE_OPTIONAL)
#end
## build rendering string
#if( $RENDERING_TYPE_OPTIONAL == '')
#set ($rendering_type = $prefix + "Rendering")
#else
#set ($rendering_type = $RENDERING_TYPE_OPTIONAL)
#end
package $PACKAGE_NAME

import com.squareup.workflow1.StatelessWorkflow
import ${PACKAGE_NAME}.${WorkflowName}.Output
import ${PACKAGE_NAME}.${WorkflowName}.Props
import ${PACKAGE_NAME}.${WorkflowName}.Rendering

#if( $PROPS_TYPE_OPTIONAL == '') ## import if we create below
import $PACKAGE_NAME.$NAME.$props_type
#end
#if( $OUTPUT_TYPE_OPTIONAL == '') ## import if we create below
import $PACKAGE_NAME.$NAME.$output_type
#end
#if( $RENDERING_TYPE_OPTIONAL == '') ## import if we create below
import $PACKAGE_NAME.$NAME.$rendering_type
#end

#parse("File Header.java")
class ${WorkflowName} : StatelessWorkflow<Props, Output, Rendering>() {
object $NAME : StatelessWorkflow<$props_type, $output_type, $rendering_type>() {

#if( $PROPS_TYPE_OPTIONAL == '') ## create if not supplied
data class $props_type(
// TODO add args
)
#end

data class Props
data class Output
data class Rendering
#if( $OUTPUT_TYPE_OPTIONAL == '') ## create if not supplied
data class $output_type(
// TODO add args
)
#end

#if( $RENDERING_TYPE_OPTIONAL == '') ## create if not supplied
data class $rendering_type(
// TODO add args
)
#end

override fun render(
renderProps: Props,
props: $props_type,
context: RenderContext
): Rendering {
): $rendering_type {
TODO("Render")
}
}