vapor-chamber API reference - v1.3.0
    Preparing search index...

    Function useVaporAsyncCommand

    • useVaporAsyncCommand — async-aware command dispatch for Vapor components used inside Suspense boundaries.

      Vue 3.6.0-beta.10 introduced proper async component hydration under VDOM Suspense. This composable wraps an AsyncCommandBus dispatch with reactive loading/error state, making it safe for <script setup vapor> components that await async operations.

      Vue 3.6.0-beta.12: component context, fallthrough prop state, and render effect state are restored after setup errors. The try/catch in dispatch below captures command-bus errors; Vue now independently ensures its internal runtime state is clean after any setup throw.

      The dispatch function returns a Promise, matching the AsyncCommandBus interface. Use this when your commands hit async transports (HTTP bridge, WS bridge) and you need awaitable results.

      Parameters

      • OptionalasyncBus: {
            dispatch: (
                action: string,
                target: any,
                payload?: any,
            ) => Promise<CommandResult>;
        }

      Returns {
          dispatch: (
              action: string,
              target: any,
              payload?: any,
          ) => Promise<CommandResult>;
          loading: Signal<boolean>;
          lastError: Signal<Error | null>;
          dispose: () => void;
      }

      // In a <script setup vapor> component under <Suspense>:
      import { useVaporAsyncCommand } from 'vapor-chamber';
      const { dispatch, loading, lastError } = useVaporAsyncCommand(asyncBus);
      const result = await dispatch('orderCreate', { items: cart });