Intent
import { Intent, Intents } from '@hurum/core'Intent(...commands)
Section titled “Intent(...commands)”Creates a sequential intent. Commands execute one after another. If any executor throws, subsequent commands are skipped.
Signature
Section titled “Signature”function Intent<TInput>(...commands: Command<TInput>[]): IntentAction<TInput>Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
...commands | Command<TInput>[] | One or more commands to execute in order. |
Returns
Section titled “Returns”An IntentAction<TInput> — both an intent descriptor and a callable function.
Example
Section titled “Example”const PurchaseIntents = Intents('Purchase', { submitClicked: Intent(ValidateCmd, SaveCmd), pageOpened: Intent(LoadCmd),})Intent.all(...commands)
Section titled “Intent.all(...commands)”Creates a parallel, fail-fast intent. All commands start simultaneously. If one fails, the others are aborted via their AbortSignal.
Signature
Section titled “Signature”Intent.all<TInput>(...commands: Command<TInput>[]): IntentAction<TInput>Example
Section titled “Example”const DashboardIntents = Intents('Dashboard', { pageOpened: Intent.all(LoadUserCmd, LoadStatsCmd, LoadNotificationsCmd),})Intent.allSettled(...commands)
Section titled “Intent.allSettled(...commands)”Creates a parallel, independent intent. All commands start simultaneously. Each runs to completion independently — a failure in one does not affect the others.
Signature
Section titled “Signature”Intent.allSettled<TInput>(...commands: Command<TInput>[]): IntentAction<TInput>Example
Section titled “Example”const SyncIntents = Intents('Sync', { syncAll: Intent.allSettled(SyncContactsCmd, SyncCalendarCmd, SyncFilesCmd),})Intents(prefix, definitions)
Section titled “Intents(prefix, definitions)”Creates a namespaced container of intents. The container is passed to Store.intents() to register intent actions on the store.
Signature
Section titled “Signature”function Intents<TPrefix extends string, TDefs extends Record<string, IntentDescriptor>>( prefix: TPrefix, intents: TDefs,): TDefs & IntentsContainerParameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
prefix | string | Namespace prefix for identification. |
intents | Record<string, IntentDescriptor> | A map of intent names to Intent(...) definitions. |
Returns
Section titled “Returns”An IntentsContainer with the same keys as intents. Each value is an IntentAction.
Example
Section titled “Example”const CartIntents = Intents('Cart', { addItem: Intent(AddItemCmd), checkout: Intent(ValidateCartCmd, ProcessPaymentCmd, ConfirmOrderCmd), refreshPrices: Intent.all(FetchPriceCmd, FetchTaxCmd),})IntentAction<TInput>
Section titled “IntentAction<TInput>”The type of each intent produced by Intent(...). It is both an IntentDescriptor and a callable function.
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
commands | ReadonlyArray<Command<TInput>> | The commands this intent will execute. |
mode | 'sequential' | 'all' | 'allSettled' | The execution strategy. |
Call Signature
Section titled “Call Signature”(payload: TInput) => PreparedIntent<TInput>Calling an IntentAction with a payload produces a PreparedIntent ready for store.send().
Example
Section titled “Example”// Create a PreparedIntentconst prepared = CartIntents.addItem({ item: newItem })
// Send itstore.send(prepared)
// Or use the shorthand (equivalent)store.send.addItem({ item: newItem })PreparedIntent<TInput>
Section titled “PreparedIntent<TInput>”An intent paired with its payload, ready to be dispatched. Created by calling an IntentAction with a payload.
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
intent | IntentDescriptor<TInput> | The original intent descriptor. |
payload | TInput | The payload to pass to each executor. |
IntentRef
Section titled “IntentRef”An opaque reference returned by store.send(). Used for cancellation.
const ref = store.send.submitClicked({ formData })
// Cancel this specific intentstore.cancel(ref)Execution Modes Summary
Section titled “Execution Modes Summary”| Mode | Function | Behavior on Failure |
|---|---|---|
| Sequential | Intent(A, B, C) | Stops at the failing command. B and C are skipped. |
| Parallel fail-fast | Intent.all(A, B, C) | Aborts all others via AbortSignal. |
| Parallel independent | Intent.allSettled(A, B, C) | Other commands continue. Error is reported via middleware. |
- Intents represent user actions or system triggers (“submit clicked”, “page opened”). Name them from the user’s perspective.
- The payload type
TInputis shared across all commands in an intent. Every executor in the chain receives the same payload. - Use
Intent()(sequential) as the default. Switch toIntent.all()orIntent.allSettled()only when parallel execution is needed.