Tutorials

Combine several UseCases for one screen

Aggregate independent snapshots at the presentation boundary while leaving atomic business coordination outside MVP.

v0.1.0-dev.1Intermediate

Combine several UseCases for one screen

A profile screen can load data and save edits through separate UseCases. MVP may present both without pretending they form one business transaction.

1. Put both snapshots in Model

dart
final class ProfileModel {
  const ProfileModel({
    required this.profile,
    required this.save,
    required this.reload,
    required this.updateName,
  });

  final UseCaseSnapshot<ProfileState> profile;
  final UseCaseSnapshot<SaveProfileState> save;
  final void Function() reload;
  final void Function(String name) updateName;
}

2. Observe both sources

ModelBinding.changes contains both replay-latest streams. After either emits, read() obtains both current snapshots. Presenter receives one complete feature input instead of a partial event.

3. Derive one screen policy

Presenter can combine loading, saving, current name, status text, and button policy into one ProfileViewState. The View never asks which UseCase is busy and does not merge two subscriptions.

4. Emit effects only for meaningful transitions

Replay-latest streams and explicit initial reads can produce equivalent snapshots. Compare previous and current save phases before emitting ProfileSaved; do not emit it unconditionally from onModelChanged.

5. Keep business coordination where it belongs

This screen-level aggregation is valid when loading and saving remain independent operations. If both must commit atomically, create one coordinating business boundary. Ark MVP neither requires nor manufactures that UseCase.

Ownership

The feature owner closes both UseCases. MvpView closes one Presenter. Model and ViewState are immutable values and own no resources.

ARKTELOS

Purpose-built engineering systems for software that has to hold.