RxSwiftCommunity / RxKingfisher

Reactive extension for the Kingfisher image downloading and caching library
MIT License
223 stars 39 forks source link

Allow Resource to be nil #2

Closed kasyanov-ms closed 6 years ago

kasyanov-ms commented 6 years ago

..to match original Kingfisher

public func setImage(with resource: Resource?,
                     placeholder: Placeholder? = nil,
                     options: KingfisherOptionsInfo? = nil,
                     progressBlock: DownloadProgressBlock? = nil,
                     completionHandler: CompletionHandler? = nil) -> RetrieveImageTask
freak4pc commented 6 years ago

Can you explain the use case ? Trying to think of when you’ll want to bind a nil image resource.

Thanks for opening the issue :)

kasyanov-ms commented 6 years ago
protocol ViewModelProtocol {
    var imageUrl: Signal<URL?> { get } // May return nil if no data from network call or we have a broken url string
}

class ViewController: UIViewController {
    func setup() {
        viewModel
            .imageUrl
            //.filter { $0 != nil }.map { $0! }
            .emit(to: artworkView.kf.rx.image(placeholder: placeholder)) // Don't compile, should uncomment the previous line and move it into the viewmodel
            .disposed(by: disposeBag)
    }
}

Also it is impossible to use dynamic nature of Signal/Driver without polluting the viewmodel with UIImage's or dublicating placeholders. For example with the code above, this sequence [goodUrl, nil, goodUrl] won't show the placeholder on the 2nd element

freak4pc commented 6 years ago

Fair point ! Will fix this soon.

freak4pc commented 6 years ago

Fixed in 0.1.1. Being deployed to CocoaPods as we speak: https://circleci.com/gh/RxSwiftCommunity/RxKingfisher/18