talenguyen / Architecture

Architecture for Android
Apache License 2.0
4 stars 0 forks source link

Love it #2

Open dbof10 opened 7 years ago

dbof10 commented 7 years ago

Looks like previous Redux sample but add ViewModel. So the View is very clean. Try it in production. The name Effect is not cool instead of Epic.

  1. We will focus on scope of Store over ViewModel, right?. How about scoping with Store like CheckoutScope, FilterScope ?
  2. After pull to refresh, loadmore not work!! Anw, I really love it. I'll write about this
talenguyen commented 7 years ago

Scoping is about how to manage dependencies scope using dagger. Basically, we should have a singleton Store in each scope.

talenguyen commented 7 years ago

I'll consider your suggestion about Epic. Thanks for your comment

dbof10 commented 7 years ago

After looking thoughtfully at the architecture, I want to say something.

  1. ViewModel seems useless in this case? Why not bind the View directly to the Store?. I suggest to rename ViewModel to something else. ViewModel reflects exactly the Model on the View. I look at Uber code
public abstract class LearnDetailViewModel extends ViewModel {
    public static LearnDetailViewModel create(List) { ... }
    public abstract List getArticles() { ... }
    abstract LearnDetailViewModel setArticles(List) { ... }
} 
public class LearnArticleViewModel extends ViewModel {
    public String getContentUrl() { ... }
    public String getImageUrl() { ... }
    public String getPreview() { ... }
    public List getTags() { ... }
    public String getTitle() { ... }
} 

int the View

public class HeroTextView extends LinearLayout {
      private final ImagePartView a;
      private final TextView b;
      private final TextView c;
    public volatile void setViewModel(ViewModel vm) { 
       a.setImage(vm.getImage());
  }
}

Any ideas?

  1. State Reducer make mostly sense if we are depending on the previous state somehow. In the “Search Screen” we are not depending on the previous state. Reducer is optional, right?

Hope we can make it better

talenguyen commented 7 years ago
  1. A very simple and common pattern is (loading-content-error). How should you design your ViewModel. In my point of view that ViewModel not only reflects what to display on View but also contain the logic of the View. So, That makes sense if some if-else are put in the ViewModel. But, If there is no logic then we can bind that ViewModle directly.

  2. Reducer is needed to compute the state depend on 2 parameters (previous state and the results). You can use both or you can use one of them.