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

Bridging RxSwift to SwiftUI #4

Open
jlevine22 opened this issue Jun 16, 2019 · 5 comments
Open

Bridging RxSwift to SwiftUI #4

jlevine22 opened this issue Jun 16, 2019 · 5 comments

Comments

@jlevine22
Copy link

jlevine22 commented Jun 16, 2019

Haven't really been able to test this out as I've been fighting with Xcode 11 and just some general bugginess but here's a first stab at this:

class Bound<Value>: BindableObject {
    let bag = DisposeBag()

    var value: Value {
        didSet {
            didChange.send(value)
        }
    }
    
    let didChange = PassthroughSubject<Value, Never>()
    
    init(_ value: Value) { self.value = value }
}

extension Observable {
    func asBindableObject(initialValue: Element) -> Bound<Element> {
        let bound = Bound(initialValue)
        subscribe(onNext: { [weak bound] in bound?.value = $0 }).disposed(by: bound.bag)
        return bound
    }
}

Thoughts?

@jlevine22
Copy link
Author

Just to follow up, I was able to use this successfully in this example project here: https://github.com/jlevine22/rxswift-to-swiftui

@freak4pc
Copy link
Member

Hey there! Thanks, I'll take a deeper look throughout the week :)

@freak4pc
Copy link
Member

@jlevine22 Only took me 6 months to get to this :( So sorry, it's been a bit hectic.
The basic concepts outlined in your repo look promising! Would you want to make a more thorough PR with these capabilities?

@ivnsch
Copy link

ivnsch commented Apr 28, 2020

Any updates on this?

@freak4pc
Copy link
Member

freak4pc commented May 4, 2020

Happy to accept a more fleshed out PR to look at. I personally don't have the time to look into it ATM :)

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

3 participants