-
-
Notifications
You must be signed in to change notification settings - Fork 7
ViewClientPresenter
Viewable presenters are those that are linked with a UI view, both the presenter and the view share the life-cycle, when a presenter is activated the view will be revealed and if the view is removed the presenter will be deactivated, we define such presenter bye extending from the ViewBaseClientPresenter
and specify the view in the generic type.
@Presenter
public class SimpleViewPresenter extends ViewBaseClientPresenter<SimpleView> {
@Override
protected void postConstruct() {
}
@Override
protected void onActivated() {
}
@Override
protected void onDeactivated() {
}
@Override
protected void onBeforeReveal() {
}
@Override
protected RevealedHandler getRevealHandler() {
return () -> {
//do something when view revealed
};
}
@Override
protected RemovedHandler getRemoveHandler() {
return () -> {
//do something when view is removed
};
}
@Override
public Optional<String> getName() {
return Optional.of("simpleViewPresenter");
}
}
In a viewable presenter the generic type is the type-of an interface that extends from View
which represent the contract between the presenter and its view, notice that the presenter does not know about the implementation of view and the framework will inject the view implementation into the presenter at runtime.
> We will discuss views in details in later parts if the documentation.
In addition to the change in base class and the generic type we notice that we have few more method that we can override here and those methods are coupled to the life-cycle of the presenter and the view together, and the life-cycle is as the following :
- A routing happens that requires the presenter to be activated.
- A new instance of the presenter is created.
- A new instance of the view is created and injected into the presenter.
- Call
postConstruct
- Register presenter events listeners.
- Fire presenter state event if such event is present. - we can make the presenter fire an event when ever its (de)activated -
- If the presenter has a name we register that presenter name in an internal registry.
- View is about to be revealed.
We will explain more about revealing views as part of this documentation.
- Call
onBeforeReveal
. - View is revealed.
- Call the
onRevealHandler
. - Later view is removed.
- Call
onRemoveHandler
- Call
onDeactivated