salsify-experiences-sdk
Version:
SDK to be used by commerce websites to implement product experiences.
68 lines (60 loc) • 1.9 kB
text/typescript
/**
* @module events
*/
import { Logger } from '../utils/logger'
import NavigationEventHandler, { NavigationEventOptions } from './navigation'
import AddToCartEventHandler, { AddToCartEventOptions } from './add-to-cart'
import EnhancedContentApi from '../enhancedContent'
/** @internal */
export interface EventsApiOptions {
beforeNavigation?: (options?: NavigationEventOptions) => void
onNavigation?: (options?: NavigationEventOptions) => void
}
/**
* This class is responsible for handling events.
*
* It is responsible for exposing the public methods for triggering each different type of event.
*/
export default class EventsApi {
/** @internal */
public constructor(logger: Logger, options?: EventsApiOptions, ecApi?: EnhancedContentApi) {
this.
this.
this.
}
/**
* Triggers the `navigation` event.
*
* @example
* ```typescript
* salsify.events.navigation({
* productIdType: "SKU",
* productId: "123",
* });
* ```
*
* @param options The options to pass to the event handler.
*/
public navigation(options: NavigationEventOptions): void {
this.
new NavigationEventHandler(this.
this.
}
/**
* Triggers the `addToCart` event.
*
* @example
* ```javascript
* const salsify = window.salsifyExperiencesSdk;
* const options = { quantity: 1, productIdType, productId };
* salsify.events.addToCart(options);
* ```
* @param options The options to pass to the event handler.
*/
public addToCart(options: AddToCartEventOptions): void {
new AddToCartEventHandler(this.
}
}