-
Notifications
You must be signed in to change notification settings - Fork 89
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
Alternative view listener injection #7
Comments
Using events emitted inside the view listeners will bring the Flux architecture to Android. Flexible architecture, explicit update path, immutable data and all other benefits of Flux. |
don't you want to separate flux approach from just the rendering/UI events handling? I think spawning the event object is exactly the same as spawning the |
@adelnizamutdinov Correct, Anvil core doesn't provide any of the UI listener bindings at all, but it allows binding in general. Then Attrs.java provide most common listener bindings like OnClickListener, which is good if you have lambdas or if you write in Kotlin, but in Java 6 it can be a pain. I was looking for some method to bind class methods easily in Java 6, because now one has either: View.OnClickListener mListener = new View.OnClickListener() {
public void onClick(View v) {
// Code here
}
};
v(SomeView.class, onClick(mListener)); // Good thing - zero garbage or v(SomeView.class, onClick(new View.OnClickListener() {
public void onClick(View v) {
// Code here
}
}); I like neither. I agree that events are no lighter than this simple click listener, but maybe some event factory could be used to not instantiate new objects, but reuse the existing ones (one per binding). Anyway, to me code lightness is more important here than the execution speed or GC. |
I decided to not include this kind of functionality. Of course one might want to write a library on top of Anvil if he find this useful. |
* add sample app module to project * update travis config * move buildscript section to parent
Currently, the easiest form of binding a view listener is to use Java 8 closures:
This is compact and clean, but it creates a new onClickListener object each time. Of course one can write listeners inside a Renderable class, but that becomes somewhat bloated:
I'm looking for some lightweight approach to use Renderable methods instead, e.g:
The first thing coming to my mind is and event bus. An event instance will be passed into a view node, then the real listener bound by Anvil will submit that event instance to the event bus and the Renderable (or any other class) would handle it.
Event objects are lightweight, which is great. I just worry about a massive amount of various event classes for each listener for each view. Any ideas?
The text was updated successfully, but these errors were encountered: