@suluk/nano-stores - v0.1.3
    Preparing search index...

    Interface CartStore

    interface CartStore {
        $items: MapStore<Record<string, CartLine>>;
        $count: ReadableAtom<number>;
        $subtotalCents: ReadableAtom<number>;
        lines(): CartLine[];
        get(
            productId: string | number,
            variantId?: string | number,
        ): CartLine | undefined;
        add(item: CartLine): void;
        setQty(
            productId: string | number,
            qty: number,
            variantId?: string | number,
        ): void;
        remove(productId: string | number, variantId?: string | number): void;
        clear(): void;
        reload(): void;
        destroy(): void;
    }
    Index

    Properties

    $items: MapStore<Record<string, CartLine>>

    lines keyed by an OPAQUE prefixed id — subscribe for reactive UI, but render from lines() (insertion order) and look lines up with get(productId). (Keys are prefixed so the JS engine preserves insertion order even for numeric product ids, which it would otherwise hoist ahead of string ids.)

    $count: ReadableAtom<number>

    total quantity across all lines.

    $subtotalCents: ReadableAtom<number>

    Σ qty·priceCents — the cart subtotal in cents (pre-discount, pre-tax).

    Methods

    • the line for a product (+ optional variant), or undefined.

      Parameters

      • productId: string | number
      • OptionalvariantId: string | number

      Returns CartLine | undefined

    • set a line's quantity; qty <= 0 removes the line. Pass variantId to target a specific variant line.

      Parameters

      • productId: string | number
      • qty: number
      • OptionalvariantId: string | number

      Returns void

    • remove a line entirely (optionally a specific variant line).

      Parameters

      • productId: string | number
      • OptionalvariantId: string | number

      Returns void