wayfair / vsm-ios

An iOS framework for the VSM Architecture
MIT License
9 stars 2 forks source link

Observe Some (Generic) Publisher #39

Closed albertbori closed 9 months ago

albertbori commented 9 months ago

Description

This PR introduces a small change which allows the observation of some Publisher<Value, Failure> instead of explicitly requiring AnyPublisher<Value, Failure>. This helps reduce the amount of typing when building view state models.

Previous:

struct LoaderModel {
    func load() -> AnyPublisher<MyViewState, Never> {
        Just(.loading)
            .merge(with: webRequestPublisher())
            .eraseToAnyPublisher()
    }
}

Current as of this PR:

struct LoaderModel {
    func load() -> some Publisher<MyViewState, Never> {
        Just(.loading)
            .merge(with: loadPublisher())
    }
}

Prior to this PR, the above code would cause an error if you tried to observe that function like so:

$state.observe(loaderModel.load())

Type of Change

Checklist