The FacetGenerator headless sub-controller creates commerce facet sub-controllers from the Commerce API search or product listing response.

Commerce facets are not requested by the implementer, but rather pre-configured through the Coveo Merchandising Hub (CMH). The implementer is only responsible for leveraging the facet controllers created by this sub-controller to properly render facets in their application.

interface FacetGenerator {
    getFacetController: <T extends FacetType>(
        facetId: string,
        facetType: T,
    ) => undefined | MappedGeneratedFacetController[T];
    state: MappedFacetStates;
    deselectAll(): void;
    subscribe(listener: () => void): Unsubscribe;
}

Hierarchy

  • Omit<CSRFacetGenerator, "state" | "facets">
    • FacetGenerator

Methods

  • Deselects all values in all facets.

    Returns void

  • Adds a callback that's invoked on state change.

    Parameters

    • listener: () => void

      A callback that's invoked on state change.

    Returns Unsubscribe

    A function to remove the listener.

Properties

getFacetController: <T extends FacetType>(
    facetId: string,
    facetType: T,
) => undefined | MappedGeneratedFacetController[T]

Builds a facet controller for the specified facet ID.

Type declaration

The state of each every facet returned by the Commerce API.

In a server-side rendering (SSR) scenario, you must use this state to render the facet UI components before the facet controller is hydrated on the client side.

Once the facet generator controller has been hydrated, you must use the getFacetController method to retrieve the individual facet controllers and subscribe to their respective states.