Skip to content

Commit 6cb5505

Browse files
authored
Merge pull request #1286 from square/ray/onPropsChanged-thanks-hannah
Updates kdoc on `onPropsChanged`.
2 parents fd1d185 + f3d58d8 commit 6cb5505

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

workflow-core/src/commonMain/kotlin/com/squareup/workflow1/StatefulWorkflow.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -787,11 +787,20 @@ public abstract class StatefulWorkflow<
787787
): StateT = initialState(props, snapshot)
788788

789789
/**
790-
* Called from [RenderContext.renderChild] instead of [initialState] when the workflow is already
791-
* running. This allows the workflow to detect changes in props, and possibly change its state in
792-
* response. This method is called only if the new props value is not `==` with the old.
790+
* Called immediately before [render] if the parent workflow has provided updated
791+
* [PropsT] that are not `==` to those provided previously. This allows the child
792+
* to update its state based on the new information before rendering.
793+
*
794+
* Note, though, that it is generally a mistake to copy information from [PropsT]
795+
* to [StateT]! [PropsT] is always available via the `renderProps` parameter
796+
* of [render], and as [props][WorkflowAction.Updater.props] for a [WorkflowAction].
797+
* This method is mainly useful if you need to switch an `enum` or `sealed` [StateT]
798+
* based on [PropsT].
793799
*
794800
* Default implementation does nothing.
801+
*
802+
* @return the new [StateT]. [render] is then called immediately with this
803+
* value as `renderProps`.
795804
*/
796805
public open fun onPropsChanged(
797806
old: PropsT,

0 commit comments

Comments
 (0)