Intent
import { Intent, Intents } from '@hurum/core'Intent(...commands)
섹션 제목: “Intent(...commands)”순차적 Intent를 생성해요. Command가 순서대로 실행돼요. Executor 중 하나가 예외를 던지면 이후 Command는 건너뛰어요.
시그니처
섹션 제목: “시그니처”function Intent<TInput>(...commands: Command<TInput>[]): IntentAction<TInput>매개변수
섹션 제목: “매개변수”| 매개변수 | 타입 | 설명 |
|---|---|---|
...commands | Command<TInput>[] | 순서대로 실행할 하나 이상의 Command. |
반환값
섹션 제목: “반환값”IntentAction<TInput> — Intent 디스크립터이자 호출 가능한 함수예요.
const PurchaseIntents = Intents('Purchase', { submitClicked: Intent(ValidateCmd, SaveCmd), pageOpened: Intent(LoadCmd),})Intent.all(...commands)
섹션 제목: “Intent.all(...commands)”병렬, fail-fast Intent를 생성해요. 모든 Command가 동시에 시작돼요. 하나가 실패하면 나머지는 AbortSignal로 중단돼요.
시그니처
섹션 제목: “시그니처”Intent.all<TInput>(...commands: Command<TInput>[]): IntentAction<TInput>const DashboardIntents = Intents('Dashboard', { pageOpened: Intent.all(LoadUserCmd, LoadStatsCmd, LoadNotificationsCmd),})Intent.allSettled(...commands)
섹션 제목: “Intent.allSettled(...commands)”병렬, 독립적 Intent를 생성해요. 모든 Command가 동시에 시작돼요. 각각 독립적으로 완료까지 실행되며 — 하나의 실패가 다른 것에 영향을 주지 않아요.
시그니처
섹션 제목: “시그니처”Intent.allSettled<TInput>(...commands: Command<TInput>[]): IntentAction<TInput>const SyncIntents = Intents('Sync', { syncAll: Intent.allSettled(SyncContactsCmd, SyncCalendarCmd, SyncFilesCmd),})Intents(prefix, definitions)
섹션 제목: “Intents(prefix, definitions)”네임스페이스가 지정된 Intent 컨테이너를 생성해요. 컨테이너는 Store.intents()에 전달해서 Store에 Intent 액션을 등록해요.
시그니처
섹션 제목: “시그니처”function Intents<TPrefix extends string, TDefs extends Record<string, IntentDescriptor>>( prefix: TPrefix, intents: TDefs,): TDefs & IntentsContainer매개변수
섹션 제목: “매개변수”| 매개변수 | 타입 | 설명 |
|---|---|---|
prefix | string | 식별을 위한 네임스페이스 접두사. |
intents | Record<string, IntentDescriptor> | Intent 이름에서 Intent(...) 정의로의 맵. |
반환값
섹션 제목: “반환값”intents와 동일한 키를 가진 IntentsContainer. 각 값은 IntentAction이에요.
const CartIntents = Intents('Cart', { addItem: Intent(AddItemCmd), checkout: Intent(ValidateCartCmd, ProcessPaymentCmd, ConfirmOrderCmd), refreshPrices: Intent.all(FetchPriceCmd, FetchTaxCmd),})IntentAction<TInput>
섹션 제목: “IntentAction<TInput>”Intent(...)가 생성하는 각 Intent의 타입이에요. IntentDescriptor이면서 호출 가능한 함수예요.
| 속성 | 타입 | 설명 |
|---|---|---|
commands | ReadonlyArray<Command<TInput>> | 이 Intent가 실행할 Command 목록. |
mode | 'sequential' | 'all' | 'allSettled' | 실행 전략. |
호출 시그니처
섹션 제목: “호출 시그니처”(payload: TInput) => PreparedIntent<TInput>IntentAction에 페이로드를 전달해서 호출하면 store.send()에 전달할 수 있는 PreparedIntent가 생성돼요.
// Create a PreparedIntentconst prepared = CartIntents.addItem({ item: newItem })
// Send itstore.send(prepared)
// Or use the shorthand (equivalent)store.send.addItem({ item: newItem })PreparedIntent<TInput>
섹션 제목: “PreparedIntent<TInput>”페이로드와 쌍을 이루어 디스패치 준비가 된 Intent예요. IntentAction에 페이로드를 전달해서 호출하면 생성돼요.
| 속성 | 타입 | 설명 |
|---|---|---|
intent | IntentDescriptor<TInput> | 원본 Intent 디스크립터. |
payload | TInput | 각 Executor에 전달할 페이로드. |
IntentRef
섹션 제목: “IntentRef”store.send()가 반환하는 불투명 참조예요. 취소에 사용돼요.
const ref = store.send.submitClicked({ formData })
// Cancel this specific intentstore.cancel(ref)실행 모드 요약
섹션 제목: “실행 모드 요약”| 모드 | 함수 | 실패 시 동작 |
|---|---|---|
| 순차 | Intent(A, B, C) | 실패한 Command에서 중단. B와 C는 건너뛰어요. |
| 병렬 fail-fast | Intent.all(A, B, C) | AbortSignal로 나머지를 모두 중단해요. |
| 병렬 독립 | Intent.allSettled(A, B, C) | 다른 Command는 계속 실행돼요. 오류는 middleware로 보고돼요. |
참고사항
섹션 제목: “참고사항”- Intent는 사용자 액션이나 시스템 트리거를 나타내요 (“submit clicked”, “page opened”). 사용자의 관점에서 이름을 지정하세요.
- 페이로드 타입
TInput은 Intent의 모든 Command가 공유해요. 체인의 모든 Executor가 동일한 페이로드를 받아요. - 기본적으로
Intent()(순차)를 사용하세요. 병렬 실행이 필요한 경우에만Intent.all()또는Intent.allSettled()로 전환하세요.