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

Initial actions #3624

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Initial actions #3624

wants to merge 5 commits into from

Conversation

stephencelis
Copy link
Member

It is common to send an action to a store when it is first created to kick off some long-living effects. While many utilize the onAppear view modifier for this work, we can simplify things by making the store's initializer a little more powerful.

It is common to send an action to a store when it is first created to
kick off some long-living effects. While many utilize the `onAppear`
view modifier for this work, we can simplify things by making the
store's initializer a little more powerful.
@stephencelis stephencelis requested a review from mbrandonw March 14, 2025 19:19
@@ -175,6 +177,9 @@ public final class Store<State, Action> {
initialState: initialState,
reducer: reducer.dependency(\.self, dependencies)
)
if let initialAction = initialAction() {
send(initialAction)

Choose a reason for hiding this comment

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

How can we send initial actions to stores created by store.scope(…)?

Choose a reason for hiding this comment

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

+1. It's rather uncommon outside of tests to use the store's initialiser directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants