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
CocoaAction Type Change #17
Comments
That's one of the reasons why I mostly use |
Submitted a pull request: #30 |
Could we use protocols to be sneaky here? Like: typealias CocoaAction = Action<ActionInput, ActionOutput> And then define those two protocols as empty and users can conform with their own types? Not sure. There's no easy answer, but I think it's an important discussion to have. |
Hmm of course Swift 3 is going to come along in a little while and then we will have generic typealiases negating all of these workarounds. We could also consider a generic type wrapped in an enum/struct for now (the usual trick) until Swift 3? I'm not a huge fan of these but could work, eg: struct GenericAction<Y, R> {
typealias T = CocoaAction<Y, R>
}
let action = GenericAction<Void, Observable<String>>.T() |
The problem comes from the |
It may sound stupid but.. why a CocoaAction has to be an Action? |
I've tried to implement it (heavily "inspired" by RAC's CocoaAction) here The main drawback is that we're losing "Sender" type inside the closure, honestly I've never used it anyway. |
Ah interesting, so it acts as like a wrapper for |
I'm not sure that introducing Action wrapper is a right way for RxCocoa users. I think our Action do not necessarily have to be the same as RAC's Action, because API design of each libraries differ from each other. RAC assumes that all actions triggered by Cocoa components is expressed as CocoaAction, but RxCocoa doesn't. Additionally, we already have a mechanism that just provides a custom input parameter on Action. let button = UIButton()
let barButtonItem = UIBarButtonItem()
let disposeBag = DisposeBag()
let action = Action<String, Void> { input in
print("\(input) is pressed.")
}
button.rx.tap
.map { _ in "UIButton" }
.bindTo(action.input)
.addDisposableTo(disposeBag)
barButtonItem.rx.tap
.map { _ in "UIBarButtonItem" }
.bindTo(action.input)
.addDisposableTo(disposeBag) Now, we have 2 choices to give a custom input parameters on Action:
Personally, I think 1 is more reasonable than 2. |
@ishkawa this is really interesting, the main problem I see is that, in this way, the button's enabled property is not in sync with the action executing state. I don't think either it's absolutely necessary to "mirror" RAC behavior, (otherwise I'd continue to use that instead of Rx.). It's not perfect at all, it's difficult to explain to new developers and has some "complications" that I don't need. Let me also clarify why I came to this kind of conclusion. Maybe I can work out something on your suggestions that doesn't involve the creation of a new class, I'll let you know. In the meanwhile, THANKS :) |
@ashfurrow should we close this? |
Let's keep it open until we add documentation to the readme? |
ok, I'm trying to do it right now BTW |
Cool, thanks! And thanks again for adding it! |
It's
<Void, Void>
right now, but it would be awesome to somehow feed input into it. The problem is we can't define a property using generics on a non-generic type. I haven't given this a tonne of thought, so there might be an obvious solution.The text was updated successfully, but these errors were encountered: