前のページの port の store の成功の値は void です。このため、store を andThen で連結すると、保存の後の map へ、保存したイベントを渡せません。最後の map は event.aggregateState を取り出すため、保存の後もイベントが必要です。図の startExaminationEvent は ExaminationStarted を生成する処理です。startExaminationEvent と store の実装は、後のページで確認します。
-
andThenで実装すると:andThenは、storeが返した値を次の行へ渡します。storeが返す値はvoidであるため、次の行へ渡されるのは、保存したイベントではなくvoidです。 -
andThenで実装すると: 次の行のeventはvoidです。voidにaggregateStateはないため、型検査のときに報告されます。 -
andThroughで実装すると:andThroughは、storeの成功を確認したあと、その結果を破棄します。次の行へは、保存したイベントがそのまま渡されます。 -
andThroughで実装すると: 次の行のeventはExaminationStartedです。event.aggregateStateを取り出して、画面に新しい予約の状態InExaminationを返せます。保存の後もイベントが必要なのは、このためです。
andThen で実装すると andThrough で実装すると 右の札は、その行から次の行へ渡される値です。✗ の札は値ではなく、型のエラーです。 .andThen の行は説明用(教材のコードにはありません)。実物: examples/session-06-solution/src/useCase/startExamination.ts:88-90 examples/session-06-solution/src/useCase/startExamination.ts:88-90 .map(startExaminationEvent(deps, input.veterinarianId)) .andThen(deps.examinationStartedStore.store) .andThrough(deps.examinationStartedStore.store) .map((event) => event.aggregateState); void に aggregateState はありません InExamination andThrough は S05 で説明した関数です。渡した処理が Ok を返すと元の値を次へ渡し、Err を返すとその Err を結果にします。