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

How to use the ConnectedView with generic state #59

Open
Amrjyniat opened this issue Mar 31, 2023 · 0 comments
Open

How to use the ConnectedView with generic state #59

Amrjyniat opened this issue Mar 31, 2023 · 0 comments

Comments

@Amrjyniat
Copy link

Amrjyniat commented Mar 31, 2023

Hi, I like the redux way of linking the Android and IOS to the store data but find some limitations while working with multiple screens, one of them was how to use the ConnectedView struct on the IOS side as a generic type and pass the correct State based on the screen because now it's bound to the FeedState, therefore, I need to create another ConnectedView(or whatever) if I want to create another screen.

Something similar to the following:

public protocol ConnectedView: View {
    ....
    func map(state: State, dispatch: @escaping DispatchFunction) -> Props
    ...
}

public extension ConnectedView {
    func render(state: State, dispatch: @escaping DispatchFunction) -> V {
        ....
    }
    
    var body: StoreConnector<V> {
        return StoreConnector(content: render)
    }
}

public struct StoreConnector<V: View>: View {
    @EnvironmentObject var store: ObservableObject
    let content: (State, @escaping DispatchFunction) -> V
    
    public var body: V {
        return content(store.state, store.dispatch)
    }
}
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

No branches or pull requests

1 participant