Skip to content
import { Intent, Intents } from '@hurum/core'

Creates a sequential intent. Commands execute one after another. If any executor throws, subsequent commands are skipped.

function Intent<TInput>(...commands: Command<TInput>[]): IntentAction<TInput>
ParameterTypeDescription
...commandsCommand<TInput>[]One or more commands to execute in order.

An IntentAction<TInput> — both an intent descriptor and a callable function.

const PurchaseIntents = Intents('Purchase', {
submitClicked: Intent(ValidateCmd, SaveCmd),
pageOpened: Intent(LoadCmd),
})

Creates a parallel, fail-fast intent. All commands start simultaneously. If one fails, the others are aborted via their AbortSignal.

Intent.all<TInput>(...commands: Command<TInput>[]): IntentAction<TInput>
const DashboardIntents = Intents('Dashboard', {
pageOpened: Intent.all(LoadUserCmd, LoadStatsCmd, LoadNotificationsCmd),
})

Creates a parallel, independent intent. All commands start simultaneously. Each runs to completion independently — a failure in one does not affect the others.

Intent.allSettled<TInput>(...commands: Command<TInput>[]): IntentAction<TInput>
const SyncIntents = Intents('Sync', {
syncAll: Intent.allSettled(SyncContactsCmd, SyncCalendarCmd, SyncFilesCmd),
})

Creates a namespaced container of intents. The container is passed to Store.intents() to register intent actions on the store.

function Intents<TPrefix extends string, TDefs extends Record<string, IntentDescriptor>>(
prefix: TPrefix,
intents: TDefs,
): TDefs & IntentsContainer
ParameterTypeDescription
prefixstringNamespace prefix for identification.
intentsRecord<string, IntentDescriptor>A map of intent names to Intent(...) definitions.

An IntentsContainer with the same keys as intents. Each value is an IntentAction.

const CartIntents = Intents('Cart', {
addItem: Intent(AddItemCmd),
checkout: Intent(ValidateCartCmd, ProcessPaymentCmd, ConfirmOrderCmd),
refreshPrices: Intent.all(FetchPriceCmd, FetchTaxCmd),
})

The type of each intent produced by Intent(...). It is both an IntentDescriptor and a callable function.

PropertyTypeDescription
commandsReadonlyArray<Command<TInput>>The commands this intent will execute.
mode'sequential' | 'all' | 'allSettled'The execution strategy.
(payload: TInput) => PreparedIntent<TInput>

Calling an IntentAction with a payload produces a PreparedIntent ready for store.send().

// Create a PreparedIntent
const prepared = CartIntents.addItem({ item: newItem })
// Send it
store.send(prepared)
// Or use the shorthand (equivalent)
store.send.addItem({ item: newItem })

An intent paired with its payload, ready to be dispatched. Created by calling an IntentAction with a payload.

PropertyTypeDescription
intentIntentDescriptor<TInput>The original intent descriptor.
payloadTInputThe payload to pass to each executor.

An opaque reference returned by store.send(). Used for cancellation.

const ref = store.send.submitClicked({ formData })
// Cancel this specific intent
store.cancel(ref)

ModeFunctionBehavior on Failure
SequentialIntent(A, B, C)Stops at the failing command. B and C are skipped.
Parallel fail-fastIntent.all(A, B, C)Aborts all others via AbortSignal.
Parallel independentIntent.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 TInput is shared across all commands in an intent. Every executor in the chain receives the same payload.
  • Use Intent() (sequential) as the default. Switch to Intent.all() or Intent.allSettled() only when parallel execution is needed.