Hi guys,
Thanks for your project, it is great).
I was wondering whether I can execute one use case with the results of the previous without callback hell?
Escaping callback hell is one of the great benefits of rxjava/reactive programming.
Although it sounds like in this case rather than combining 2 UseCases in the presentation layer, you want one new UseCase that encompasses everything you need for this different use case.
Escaping callback hell is one of the great benefits of rxjava/reactive programming.
That why I like ractive and Android-CleanArchitecture pattern.
Although it sounds like in this case rather than combining 2 UseCases in the presentation layer
For example: when I receive results from one use case I need to pass them to the another use case. That approach leads to such code:
firstUseCase.execute(new DefaultSubscriber<String>() {
@Override
public void onNext(String s) {
secondUseCase.execute(new DefaultSubscriber<String>() {
@Override
public void onNext(String s2) {
// Grab the results.
}
});
}
});
Do you suggest to create separate use case that encapsulates previous use cases?
I also think that using composition here is better, if you create a new use case you will have the ability to reuse it at a later time.
@alexandru-calinoiu yes, that sounds a nice solution.
Additionally I faced a situation when base use case returns all entities, but in one of the presenters where I want to use that use case I want to perform for example filtering or sorting.
My question is: what is the right way to implement this filtering(encapsulate this filtering in the use case, perform it after I'll receive results from use case)?
I see 2 options in this case:
Use RxJava! You have many operators to compose observables:
https://github.com/ReactiveX/RxJava/wiki/Alphabetical-List-of-Observable-Operators
@android10 yep, but UseCase class doesn't provide access to the Observable directly.
@amatkivskiy it all depends from case to case but I see filtering of certain content as a domain or even data layer concern. Filtering is a data manipulation and If the filtering is only going to be perform in a really specific scenario, you could :
Other consideration would be if this filtering has to be done in a global scale for the entire application scope. Then I would filter all content in the data layer (in the repositories), in order to make sure we are always manipulating the already filtered collection of items.
@jatago in my case I have a situation when one use case client wants all content as is, but another client want it to be sorted or filtered.
@android10 as the guy said, UseCase#execute() does not return Observable, do you mean calling UseCase#buildUseCaseObservable() directly from outside?
Most helpful comment
@android10 yep, but UseCase class doesn't provide access to the Observable directly.