Skip to content

Commit 4a5b28f

Browse files
Adding details to the parent dependencies section of the WorkflowSwiftUI Adoption Guide (#337)
1 parent 70907f3 commit 4a5b28f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Documentation/WorkflowSwiftUI Adoption Guide.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,23 @@ struct ChildWorkflow: Workflow {
534534
}
535535
```
536536

537+
<details>
538+
<summary>Expand to see details on the above example.</summary>
539+
540+
1. Mutating `state.name` will trigger a body re-evaluation for views that observe `name` because ChildState’s `name` field is a String type. The String type is not observable.
541+
- Under the hood, the `ObservableState` macro will generate wrappers for each of its struct’s properties. When the property is modified, these wrappers will check if the new value’s identity is equal to the old value’s identity:
542+
- if the identities are equal, no mutation is observed.
543+
- if the identities are not equal, a mutation will be observed.
544+
- *See `ObservationStateRegistrar`’s `mutate(...)` function for implementation details.*
545+
- String is not observable and will always fail its identity check against another String.
546+
2. Reassigning `state.info` won’t trigger a body re-evaluation because `MiscInfo` is itself an observable type.
547+
- `ObservableState` endows structs with concept of identity, allowing them to behave similarly to class types.
548+
- In this Workflow example, the `MiscInfo` supplied from the parent workflow will have the same identity as the `MiscInfo` supplied from the parent workflow’s previous rendering. Because the identities of the two structs are the same, a mutation will not be observed.
549+
- In WorkflowSwiftUI, this `workflowDidChange(...)` function is executed after the underlying state has been mutated from a Binding. In these cases, the view will have already been invalidated if it observed this struct’s fields.
550+
3. Similar to 1 above, if ChildWorkflow had a `var foo: String` property and executed `state.info.foo = foo` within `workflowDidChange(…)`, this will trigger a body re-evaluation for views that observe `foo`. This is because the String type is not observable.
551+
552+
</details>
553+
537554
## Previews
538555

539556
`WorkflowSwiftUI` has conveniences for creating static previews based on a view or screen, or stateful preview of a workflow and screen.

0 commit comments

Comments
 (0)