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

We need 'Action' similar to RAC's 'Action' or how to solve this with RxSwift? #254

Closed
Fab1n opened this issue Nov 12, 2015 · 14 comments
Closed

Comments

@Fab1n
Copy link

Fab1n commented Nov 12, 2015

Imagine, we have a function like func openAlert() -> Observable<AlertResponse> where AlertResponse contains .OK and .Cancel for an alertView which has an OK and Cancel button.
Now I want to know if the observable is currently active and bind this information to a - let's say - button's rx_enabled state to make clear that while the action is ongoing, the button can't be pressed.
Doesn't make so much sense for Alerts, but here is another example:

On button tap, a server request is sent. How can I easily bind the button's rx_enabled subject to the actions ongoing state?

It is quite common that I want to know if some action is currently active or not.

How to solve this in a nice way with RxSwift?

@kzaher
Copy link
Member

kzaher commented Nov 12, 2015

@Fab1n Take a look at RxExample app. We use ActivityIndicator class in Wikipedia image search and Github repository search example.

ActivityIndicator is pretty generic.

The trick is to use using operator and treat ActivityToken as resources.

That's how I would do it, not sure if there is some nicer way :)

Note:
Driver class is there to guarantee and express that we want to receive those "is it running" elements on main thread, that observable can't error out and is sharing subscription.

We could have exposed _variable.asObservable(), but this was kind of nicer way of communicating properties of that observable sequence.

@Fab1n
Copy link
Author

Fab1n commented Nov 12, 2015

Ok thank you 😀

I will have a look at it tomorrow

Am 12.11.2015 um 10:42 schrieb Krunoslav Zaher notifications@github.com:

@Fab1n Take a look at RxExample app. We use ActivityIndicator class in Wikipedia image search and Github repository search example.

ActivityIndicator is pretty generic.

The trick is to use using operator and treat ActivityToken as resources.

That's how I would do it, not sure if there is some nicer way :)

Note:
Driver class is there to guarantee and express that we want to receive those "is it running" elements on main thread, that observable can't error out and is sharing subscription.

We could have exposed _variable.asObservable(), but this was kind of nicer way of communicating properties of that observable sequence.


Reply to this email directly or view it on GitHub.

@ashfurrow
Copy link
Collaborator

Looking forward to this!

@ashfurrow
Copy link
Collaborator

I've begun working on something like this here: https://github.com/ashfurrow/Action Still very early, and it's very scaled down from ReactiveCocoa's version, but I think it's a good start.

@kzaher
Copy link
Member

kzaher commented Nov 18, 2015

Hey @ashfurrow ,
If you are looking for a way how to track activity, we've got something in RxExample app. We didn't export it to a separate project, but it's pretty simple :)

https://github.com/ReactiveX/RxSwift/blob/642b84e946792cb22ca72613b0410132d6edf5f2/RxExample/RxExample/Services/ActivityIndicator.swift

It will aggregate activity from multiple observables.

Let me know what you think ...

@ashfurrow
Copy link
Collaborator

Neat! I'll have to take a closer look once I've had my coffee ☕️

@kzaher
Copy link
Member

kzaher commented Nov 18, 2015

It looks to me that Action = ActivityIndicator + flatMapLatest + some small additional juice :)

@ashfurrow
Copy link
Collaborator

Opened an issue to do it, I can't spare too much time on it right now but I'll see what I can do. Thanks so much for the suggestion!

@fpillet
Copy link
Contributor

fpillet commented Nov 20, 2015

Action is awesome, thanks!

@Fab1n
Copy link
Author

Fab1n commented Dec 4, 2015

ActivityIndicator is really great! Thank you! Maybe we should make it an official API. Should we keep this issue open until we have it?

@kzaher
Copy link
Member

kzaher commented Dec 5, 2015

We have some related projects grouped under RxSwiftCommunity organization.

I'm thinking maybe it would be good idea to add ActivityIndicator to some of them. Maybe RxViewModel. That is kind of @esttorhe's baby, so it depends what is his vision for that project :)

I'll probably create a new project under RxSwiftCommunity for reactive data sources for table and collection views. What is currently in RxDataSourceStarterKit and polish that code.

If people like @ashfurrow Action that much, maybe it would also make sense to move it under RxSwiftCommunity to better promote it.

@ashfurrow
Copy link
Collaborator

Yup! I've been discussing moving it over, but it needs to be "production ready" first. I have one remaining issue to get it there, but it needs replayAll, which will be in RxSwift's next release.

@esttorhe
Copy link

esttorhe commented Dec 5, 2015

@kzaher hahaha. It was my baby now is part of the community.

I think ActivityIndicator would work great on RxViewModel

@kzaher
Copy link
Member

kzaher commented Dec 30, 2015

We can probably close this issue for now.

@kzaher kzaher closed this as completed Dec 30, 2015
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

5 participants