Comments (7)
Hi,
getView()
looks like a workaround to me, its elimination was a matter of time.
Do you have a use case for it?
from nucleus.
My presenter calls methods on the associated view, but I'm not using Rx. Ususally just "getView().setFoo( true );" I'm sure I can do the same with the observable returned by RxPresenter.view(), but I'm not using that functionality, so it seems odd to need it. For now I've just defined my own view in my presenter class and am setting it during onTakeView.
from nucleus.
Sounds reasonable.
I was planning to completely drop non-rx part of the library.
Why are you avoiding rx?
For me the perfect presenter looks like a some kind of rx subject, that receives views+requests and emits data.
from nucleus.
I'm mostly avoiding it because:
- It's ugly, and retrolambda (which cleans it up a bit) seems like such a hack that I'm hesitant to use it.
- I'm still learning Java/Android, and Rx is like an entire meta-language on top of that.
- It's confusing as all hell, even after reading a bunch of tutorials.
My understanding, regarding 1), is that this:
getView().setFoo( true );
... will become something like this:
view().subscribe( new Action1<SomeActivity>() {
@Override
public void call( SomeActivity someActivity ) {
someActivity.setFoo( true );
}
} );
That's just ugly, and non-necessary.
from nucleus.
Ok, I've got your point. I do not use retrolambda as well. :)
Do you know that calling getView()
everywhere will sooner or later lead to NPE?
You don't need getView
during onTakeView
, but after onTakeView
the view can be dropped at any moment, leaving you with NPE.
Rx guarantee that the callback is called only when getView()
is not null. If you're not using rx you will need to make all that callbacks yourself and duplicate rx functionality on your own.
from nucleus.
Regarding NPE, I generally do null checks. If they get too cumbersome, I just wrap the whole thing in an update function that does an early out if getView() is null.
Btw, it looks like RxPresenter calls view.onNext(null); during onDropView. Doesn't that mean a null check within the observable will be necessary?
Regarding Rx in general; I find it difficult to wrap my head around how to handle everything. As an example, one case where I'm using it is: I have a RecyclerView with N objects in it. When you click one, it calls all the way back to the presenter, passing the ID of the clicked object. I needed to debounce those clicks before taking action, and after struggling a bit I ended up with an entire list of PublishSubjects, that mirrors the list of objects, to handle the clicks because I couldn't figure out how to get the debouce to work on a per-ID basis with just a single publish subject or observable.
from nucleus.
Yes, view()
requires to make null checks. This observable was first designed to be used by deliverXXX
methods internally. Nulls are needed to prevent memory leaks inside of combineLatest
, but now I think that I need to split view()
into takes()
and drops()
somehow.
I will keep getView()
. I may probably subclass Presenter
to make OldSchoolPresenterWithGetView
or something. :D
Thanks for the feedback.
from nucleus.
Related Issues (20)
- Best practice for normal case. (get support.) HOT 3
- Wondering about multiple Presenter endpoint calls (Question) HOT 2
- How to get onComplete using restartable methods? HOT 1
- How could i force restartableFirst.onError with mockito? HOT 1
- RxJava latest version not used. HOT 1
- Console error saving file HOT 1
- Activity method called every time HOT 2
- (Question) Don't keep activieties option HOT 1
- Confusion about restartables and the Activity lifecycle HOT 3
- Does Nucleus support native Fragments? HOT 2
- Throwing VerifyError in < API 21 HOT 1
- Question regarding getView() and reference the View in the presenter. HOT 11
- Nucleus with Dagger 2 HOT 3
- NucleusActionBarActivity with support library 26 HOT 13
- Help with injecting Presenter when using AndroidInjector HOT 3
- Calling setPresenter in OnCreate HOT 2
- clear the delivery cache
- Crashes when starting a new activity using kotlin
- upgrade a new version for androidx, please
- getView() deprecated
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 nucleus.