Comments (3)
I think the Rx subscription may not be related to singleton use case.
The Rx subscription will be disposed when Activity
's lifecycle goes to onDestroy
, but it won't destroy the use case instance. The whole idea is each use case responsible for a different business logic, and it can be shared between multiple Presenters.
e.g.
ArticleListPresenter
is a consumer of GetArticleListUseCase
and GetArticleTypeUseCase
, it shows articles list and types list on that screen.
Imagine we got another screen, then we have a presenter called DashboardPresenter
, this screen shows multiple sections(article list, user list, message list), so this DashboardPresenter is a consumer of GetArticleListUseCase
too, the first time when user open article list screen, GetArticleListUseCase
makes a network request and then hold the data, on the next screen, the DashboardPresenter
uses the same UseCase instance rather than create a new instance, it would have a better performance(it doesn't need to make a new network call). and it can be shared data between multiple screens.
from clean-architecture-android-kotlin.
The idea is good, but your implementation will not allow it. Your use case is not a memory cache, it will perform a repeated network call when you call execute. But rotate the screen or press back and open the application and your network call will be canceled at all, because you called it after dispose()
. Perhaps you need to recreate CompositeDisposable
, or you can use the clear()
.
from clean-architecture-android-kotlin.
That is an example and I didn't implement the memory cache on domain layer at the moment, the current use case doesn't have memory cache, it will make a new call every time when the consumer subscribes it, we could simply add .replay()
to the Rx chain, then it won't make new request after the first network call.
For the 2nd issue you mentioned:
Yes, I agree, the current use case is a singleton object, the use case and CompositeDisposable
won't be re-created after rotates. I didn't notice that before. Thanks for your contribution @AntonKulykov , I'll fix it.
from clean-architecture-android-kotlin.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clean-architecture-android-kotlin.