Learn
Lifecycle and ownership
Understand PresenterSession states, Model transitions, invalidation, closure, and the ownership boundary around business objects.
Lifecycle and ownership
One Presenter instance belongs to one session.
created → active → closing → closed
Attachment order
- Create Presenter and attach the initial Model.
- Subscribe to invalidations and effects.
- Start the session and invoke
onModelAttachedonce. - Build the initial ViewState.
Subscribing before start() is essential because onModelAttached may invalidate presentation or emit an initial effect.
Model transitions
updateModel(current) stores the current Model before calling onModelChanged(previous, current). Every change signal creates a transition; Ark MVP does not discard equal Models because application equality may omit information important to presentation.
Rebuilding ViewState
The host asks Presenter to rebuild when Model changes, Presenter calls invalidateView(), or the presentation environment changes. buildViewState must derive data only; it must not dispatch commands, navigate, or emit effects.
Closing
close() invokes closePresenter() once and closes output channels even if Presenter cleanup fails. A closed Presenter cannot be attached again. Reuse would carry stale state and subscriptions across feature boundaries.
Ownership table
| Resource | Owner |
|---|---|
| UseCase, state manager, Repository-facing coordinator | Application composition |
| ModelBinding | The object that created the binding |
| Presenter and Presenter-local resources | PresenterSession or MvpView |
| Flutter controllers and animation resources | Rendering StatefulWidget |
Closing a View closes Presenter, not the business sources captured by ModelBinding.