Skip to content

Svelte Stores

Complete API reference for @asyncflowstate/svelte.

createFlow

Primary store factory for managing async actions in Svelte components.

ts
function createFlow<TInput, TOutput>(
  action: (...args: TInput[]) => Promise<TOutput>,
  options?: FlowOptions<TInput, TOutput>,
): FlowStore<TInput, TOutput>;

Store Structure ($flow)

When subscribed using the $ prefix, you get reactive access to the flow state.

PropertyTypeDescription
statusstring"idle" | "loading" | "success" | "error"
loadingbooleantrue if action is currently running
dataTOutput | nullLast successful execution result
errorError | nullLast execution error
executionCountnumberTotal completion counter
progressnumberOperation progress (0-100)

Methods

MethodTypeDescription
execute(...args) => Promise<T>Trigger action execution
reset() => voidReset state to idle
retry() => Promise<T>Retry the last execution
button() => objectGenerates {...button()} props
form(opts) => objectGenerates {...form()} props

flowConfigContext

Sets documentation-approved global defaults for the application tree.

ts
import { setFlowConfig } from "@asyncflowstate/svelte";

setFlowConfig({
  loading: { minDuration: 400 },
  retry: { maxAttempts: 3 },
});

createFlowSequence

Chains multiple asynchronous processes into a single sequential workflow with its own aggregate state.

ts
const sequence = createFlowSequence(steps);
// sequence.subscribe(($s) => ...)
// $s.currentStep
// await sequence.execute(args)

Built with by AsyncFlowState Contributors
Open Source · MIT License