-
Notifications
You must be signed in to change notification settings - Fork 150
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
Creating a CocoaAction correctly #26
Comments
Hey there! OK, a few things, and these should be added to our documentation because you questions are really common.
OK so you can map any observable to be an observable.map { _ in Void() } I do this so often I have a function to do it for me: observable.map(void) I wouldn't recommend Observable<Int>.interval(4.5, scheduler: MainScheduler.instance) OK, so I would rewrite things like this: let newAction = CocoaAction {
let requestObservable: Observable<Bool> = Observable<Int>.interval(self.pollInterval, scheduler: MainScheduler.instance).map { _ in return true } // Just for testing
return requestObservable.flatMap { resultFromFirstObservable in
// Pretend I do something useful with my result from the first Observable.
// Maybe subscribe to another observable to do some work or something.
}.map{ _ in return Void() } // Makes an Observable<Void> so the type matches with CocoaAction.
} Let me know if that makes sense! Happy to clarify further. |
Thanks Ash, that clears things up. I'll add a few notes to the documentation issue. |
Thanks! That would be great 🙇 |
@ashfurrow We have a link to this question in #27, and I think that's enough to keep track of necessary documentation improvements. Let's close this ticket. |
Makes sense to me. @morgz sound okay to you? |
Hey @morgz , Since it's been two months with no response and it seems like your question was answered, I'm closing this for now. If you need any more help feel free to reopen or comment here ! Cheers :) |
Yes, sorry for the lack of response. Thanks guys, appreciate the hard work |
Hey,
Thanks for the library! I think I'm starting to understand it. I was using rx_tap on a button but have since switched to trying CocoaAction for the enabling/disabling functionality.
Can you just quickly sense check a few of my understandings? I have the following block of code that is just an Action. When it's invoked, it completes after a 4.5 sec delay.
requestObservable
. I have to return anObservable<Void, Void>
.rx_action
is expecting anObservable
so it can use.bindTo(self.x_enabled)
etc.Does that sound about right?
The text was updated successfully, but these errors were encountered: