API 概要
PulsePlatform は役割ごとに 1 つのパッケージを公開しています。ルールは jp.kaleidot725.pulse.architecture(architecture アーティファクト)にあります。ライブラリは jp.kaleidot725.pulse.mvi にあり、デスクトップ向けに mvi-desktop、Android と iOS 向けに mvi-mobile として公開しています。Navigation 3 対応は jp.kaleidot725.pulse.navigation にあり、navigation-desktop と navigation-mobile として公開しています。
ルール
テストから呼ぶアサートと、その土台のクエリです。ルール API の内容は、検査がどちらかを明記している場合を除き、デスクトップとモバイルのコードの両方に当てはまります。
| アサート | 説明 |
|---|---|
assertPulseMviConventions | 続く 12 の検査を順に実行する |
assertStatesAreDataTypes | PulseState は data class または data object |
assertMessagesAreSealedOrDataTypes | メッセージは data class / data object のケースを持つ sealed class、または単独の data class / data object |
assertStatesAndMessagesLiveInContracts | State とメッセージは ViewModel か Container の隣の …Contracts.kt に置く |
assertViewModelsAndContainersAreNamedAfterTheirBase | …ViewModel と …Container |
assertViewModelsHoldTheirDataInTheirState | ViewModel と Container は var プロパティを持たない |
assertViewModelsLiveInContents | ViewModel は content の下に置く |
assertContainersLiveAtTheFeatureRoot | Container は feature のルートに置く |
assertHostsComposeContents | Host は …Host という名前で、ViewModel を束ねず Content を並べる |
assertFeaturePackagesHaveARole | feature の中のファイルは、ルートか content・section・component の下にある |
assertContentsBindAViewModel | Content は PulseContent で ViewModel を束ねる |
assertSectionsAndComponentsArePure | Section と Component はデータとコールバックだけを受け取る |
assertSectionsAndComponentsHavePreviews | すべての Section と Component に <Name>_Preview がある |
assertPulseMobileConventions | mvi-mobile のアプリ向けの検査を順に実行する |
assertMobileFeaturesHaveOneViewModel | モバイルの ViewModel は feature のルートに 1 つだけ置く |
assertScreensBindTheirViewModel | モバイルの feature のルートの Composable は ViewModel を結びつける …Screen |
assertMobileFeaturePackagesHaveARole | モバイルの feature の中のファイルは、ルートか section・component の下にある |
assertPulseDomainConventions | Repository は Flow を公開し、ワンショットの取得は Result<V, E> で返す。UseCase は usecase に置き、1 行にしない |
assertPulseModuleConventions | モジュール間の依存が Clean Architecture の向きに従い、domain・data・designsystem がパッケージで分かれている |
assertPulseKoinConventions | Koin モジュールは app モジュールで定義する |
assertPulseResourceConventions | domain は文言を持たず、Composable は文言を文字列リソースから読む |
PulseModuleLayout | どのモジュール名がどの層に当たるか |
ライブラリ
PulseViewModel、PulseContent、次の 3 つのマーカーは mvi-desktop と mvi-mobile の両方にあります。モバイルの PulseViewModel は型パラメータを 5 つではなく 3 つ取ります。
| 宣言 | 説明 |
|---|---|
PulseViewModel | 1 つの UI 状態を持ち、Action を処理して Event を発行する抽象基底クラス |
PulseContent | ViewModel を観測し、状態と Action のディスパッチャを渡す |
PulseState | クラスを ViewModel の UI 状態として印付ける |
PulseAction | クラスをユーザーの操作として印付ける |
PulseEvent | クラスを一度きりの副作用として印付ける |
デスクトップ
mvi-desktop だけにあるものです。
| 宣言 | 説明 |
|---|---|
PulseContainer | ウィンドウの ViewModel 群を調整する |
PulseHost | Container をサブツリーにスコープし、Refresh と Broadcast のコールバックを渡す |
PulseBroadcast | クラスを Container の Broadcast メッセージとして印付ける |
PulseUnicast | クラスを子から親への Unicast メッセージとして印付ける |
拡張
Navigation 3 対応は任意で、どのプラットフォームでも同じように使えます。デスクトップ向けは navigation-desktop、Android と iOS 向けは navigation-mobile です。モバイルには Container がないので、rememberPulseContainer は navigation-desktop だけにあります。
| 宣言 | 説明 |
|---|---|
rememberPulseViewModel | ViewModelStoreOwner にスコープされた ViewModel |
rememberPulseNavEntryDecorators | ViewModel をバックスタックエントリにスコープする NavDisplay のデコレータ |
rememberPulseContainer | ViewModelStoreOwner にスコープされた Container(デスクトップのみ) |