Skip to content
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

Improve docs for sharing logic in parent and child features. #2638

Merged
merged 5 commits into from
Dec 11, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,28 @@ store.send(.textFieldChanged("Hello") {
}
```

##### Sharing logic in child features

There is another common scenario for sharing logic in features where the parent feature wants to
invoke logic in a child feature. One can technically do this by sending actions from the parent
to the child, but we do not recommend it (see above in <doc:Performance#Sharing-logic-with-actions>
to learn why):

```swift
// Handling action from parent feature:
case .buttonTapped:
// Send action to child to perform logic:
return .send(.child(.refresh))
```

Instead, we recommend invoking the child reducer directly:

```swift
case .buttonTapped:
return Child().reduce(into: &state.child, action: .refresh)
.map(Action.child))
```

### CPU intensive calculations

Reducers are run on the main thread and so they are not appropriate for performing intense CPU
Expand Down