About controller's usage
See original GitHub issueExcuse me for interrupting you again,I have a problem in usage of controller。 Here is the usage scenario: first,i add a loadingModel to controller,like this: ` @AutoModel LoadingEpoxyModel loadingModel;
@Override
protected void buildModels(List<String> data) {
loadingModel.addTo(this);
}`
the view display is a progress full screen. At the same time,i request data from server,in response to the data from the server,i can do:
- if the status code returned from the server is ok,and the data is not empty,i want to remove/hide loadingModel,add dataModels.
- if the status code returned from the server is ok,but the data is empty,i want to remove/hide loadingModel,add emptyModel,user click this emptyModel,i want to remove/hie emptyModel,add loadingModel.
- if the status code returned from the server is error,may be due to the bad internet connection,i want to remove/hide loadingModel,add errorModel,user click this errorModel,i want to remove/hie emptyModel,add loadingModel.
My confusion is here,the wiki said :controller not include remove/hide methods about models,so i can not remove/hide loadingModel.i try to use addIf,Unfortunately,i found that it have limits in supporting three case above. Maybe Typed Controllers can solve this problem.But i have no idea. I know Epoxy Adapter can solve this problem,but i want to use controller follow you. dou you have some suggestion? finally,please forgive me for my bad English if it annoys you.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
@ailuoyi basically, the idea is to get rid of complex state and mutability. Instead of your view being some stateful thing that you tell to change (typical MVP) you can think of the view as some kind of function-like blackbox that takes in a POJO (your UI state) and returns the appropriate user interface. Every time an event happens, you create a new POJO that contains all of your current app state and tell the view layer to render that. In this case, you construct a list of POJOs/
EpoxyModel
s inbuildModels
and give it to Epoxy, which will render this new state, regardless of which models were in it before.This idea comes from functional languages and can give you a very unidirectional, predictable data flow without side effects. In a language like Haskell or Elm you can relatively easily construct your whole app as a single function composed of other functions that only transform a single flow of data:
then your whole progam is basically:
render(handleEvent(state, event))
Happy to help, and no worries about your English, it’s good enough 😃
If I’m understanding your case, I think you can do something like this:
The reason why the controller doesn’t support removing models is that every time
buildModels
is called you start with a completely empty model state and rebuild it from scratch. Ideally you have some sort of Data object representing all of the state and you can decide what models to add to reflect that state.Epoxy doesn’t force you to use a certain data pattern, so you might use an activity/fragment/presenter/whatever, but that presenter should coordinate the network request, update the data state as necessary, and set that data on the controller when it changes so the controller can rebuild models.
Hope that helps! let me know if I can explain it more