Skip to content
Discussion options

You must be logged in to vote

Here's a pattern I often use to coordinate child domains with shared state without having to pass it down every level. With @Dependency, creating and sharing clients is lightweight so I'll just make a client supporting a given feature.

Just an example of the idea, not at all tested.

/// This client relays data from root to any child
struct FeatureClient {
    var updateValue: (Value) await -> Void
    var observeValue: () -> AsyncStream<Value>
}

struct RootFeature: ReducerProtocol {
    struct State {
    }
    enum Action {
        case task
    }
    @Dependency(\.stocksClient) var stocksClient
    @Dependency(\.featureClient) var featureClient
    func reduce() -> Effect {
        switch

Replies: 4 comments 14 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by br-dev
Comment options

You must be logged in to vote
2 replies
@Alex293
Comment options

@rcarver
Comment options

Comment options

You must be logged in to vote
3 replies
@rcarver
Comment options

@tylerjames
Comment options

@rcarver
Comment options

Comment options

You must be logged in to vote
9 replies
@br-dev
Comment options

@rcarver
Comment options

@tgrapperon
Comment options

@rcarver
Comment options

@tgrapperon
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants