-
Notifications
You must be signed in to change notification settings - Fork 222
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
Shared state #202
base: main
Are you sure you want to change the base?
Shared state #202
Conversation
Co-authored-by: Stephen Celis <[email protected]>
|
||
public init(config: ServerConfig = ServerConfig()) { | ||
self.config = config | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an FYI, but after experimenting with this approach of wrapping some shared state in a property wrapper in my app I did find a serious issue with this initializer - it can trigger an infinite view body render loop if invoked from a view body.
This can be easily done, for example if you have some child feature that uses it:
@Reducer
struct Child {
struct State: Equatable {
@ObservationStateIgnored @ServerConfig_ var config
}
}
Then you initialize the child state in a view (e.g. to pass to NavigationLink(state:)
), and that view's state also uses the property wrapper, this causes the property wrapper on the child to initialize, which in term updates the shared state, which triggers the parent view to update, which calls body
and the loop begins.
I think its better to provide just an empty initializer.
This PR builds upon #200 (which we will merge soon) in order to start making use of
@Shared
throughout the code base. The main thing left to do is fix tests.