Skip to content

How to use the ConnectedView with generic state #59

@Amrjyniat

Description

@Amrjyniat

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)
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions