2.0 Beta

Smootify 2.0 is in public beta. Your 1.x store keeps working. Move when you want.

What changed

Smootify.on()

listens to an event; `replay` also calls the handler with the last payload of one that already happened. Returns the unsubscribe.

v2.0 beta
Open .md
On this page
  1. Types
  2. SmootifyEventName
  3. SmootifyShortEventName
  4. SmootifyEventHandler

listens to an event; replay also calls the handler with the last payload of one that already happened. Returns the unsubscribe. New in 2.0.

on<N extends SmootifyEventName | SmootifyShortEventName>( name: N, handler: SmootifyEventHandler<N>, options?: { replay?: boolean }, ): () => void

Types

SmootifyEventName

export type SmootifyEventName = keyof SmootifyEventMap;

SmootifyShortEventName

/** A `smootify:` event by its name alone: `cart_updated`, `wishlist:changed_product`. */
export type SmootifyShortEventName = {
  [K in SmootifyEventName]: K extends `smootify:${infer Short}` ? Short : never;
}[SmootifyEventName];

SmootifyEventHandler

export type SmootifyEventHandler<N extends SmootifyEventName | SmootifyShortEventName> = (
  payload: SmootifyEventMap[FullEventName<N>],
) => void;

    ↑ ↓ to moveEnter to openEsc to close