-
Notifications
You must be signed in to change notification settings - Fork 151
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
Clarify documentation #27
Comments
Hey Ash, So from my initial experience of CocoaAction, the following things confused me: This code in the readme isn't valid code right? the x = y = z format is confusing and the below code doesn't compile.
Looking at the above example I was expecting something like this to compile, and quite honestly still don't understand why it doesn't! EDIT: I do now! Keep reading
or
The error is: Declared closure result & this one doesn't compile either:
From the documentation what I think I'm doing here is creating an Action that I can then call .execute() on at a later date. OK!! In writing this I've figured it out. I wasn't giving the compiler enough info on the input generic. The following 2 work:
OR
Now I might have figured out what I was doing wrong if the following example, didn't use CocoaAction but instead constructed a plain Action itself: Overall, it feels like there are 2 main options:
& Both need a good complete working example. |
Yup yup. This is the correct code, I'll update the readme: action : Action<String, Bool> = Action(workFactory: { input in
return networkLibrary.checkEmailExists(input)
}) Let me know if that clarifies things for now. Otherwise, we should heed these suggestions 👍 |
Updated: b620bf3 |
Nice. Personally I'd have found an example like this useful too:
I'm converting this project to RxSwift while learning. It seems common to define the Action in a ModelView and then just construct a CocoaAction in the viewController which executes the Action. The viewController can then observer the ModelView's Action to update view. |
Yeah, we're trying to figure out a general-purpose solution to that, too. See: #17 |
Hi guys, am I doing this correctly? I init my view model by passing in some Drivers props from vc, class SomeViewModel {
let loginAction: Action<Void, Void>
let ...
init(email: Driver<String>, password: Driver<String>) {
self.loginAction = Action<Void, Void>() { _ in
return Observable
.combineLatest(email.asObservable(), password.asObservable()) { (email: $0, password: $1) }
.flatMapLatest({ (params) in
return provider.login(params)
})
.map { _ in Void() }
}
...
}
} and then I assign the loginAction to my button's rx_action However, when the action got executed, the It seems there is a retain cycle somewhere which causes this, any idea? Thanks! |
@zipme this is a good question, and I'm not sure since I've not used class SomeViewModel {
let loginAction: Action<Void, Void>
let ...
init(email: Driver<String>, password: Driver<String>) {
self.loginAction = Action<Void, Void>() { _ in
return Observable
.combineLatest(email.asObservable(), password.asObservable()) { (email: $0, password: $1) }
.take(1) // Note the new line
.flatMapLatest({ (params) in
return provider.login(params)
})
.map { _ in Void() }
}
...
}
} And let us know if that works? |
@ashfurrow IT WORKS! Thanks Ash! You are awesome! ❤️ |
Glad to hear it! Ash Furrow On April 23, 2016 at 3:56:11 AM, zipme ([email protected](mailto:[email protected])) wrote:
|
Questions like this one are pretty common and demonstrate incomplete documentation and examples.
The text was updated successfully, but these errors were encountered: