THIS IS ARCHIVED DOCUMENTATION

ExecuteTrigger (Deprecated)

The ExecuteTrigger controller handles execute trigger actions.

Methods

subscribe

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.

Attributes

state

The state of the ExecuteTrigger controller.

Properties

  • functionName: string

    The name of the function to be executed.

  • params: (string | number | boolean)[]

    The parameters of the function to be executed.

Initialize

buildExecuteTrigger

Creates a ExecuteTrigger controller instance. An execute trigger is configured in the Administration console, and used to execute a function in the browser when a certain condition is met.

Parameters

  • engine: SearchEngine

    The headless engine.

Returns ExecuteTrigger

Unsubscribe

Call signatures

  • (): void

Example Implementation

execute-trigger.tsx

import {
  buildExecuteTrigger,
  SearchEngine,
  ExecuteTriggerParams,
} from '@coveo/headless';
 
/**
 * This sample creates an instance of the headless execute trigger controller
 * and shows how to utilize the controller with the user defined functions.
 *
 * @param engine - a headless search engine instance
 * @returns An unsubscribe function
 */
export function bindExecuteTrigger(engine: SearchEngine) {
  const controller = buildExecuteTrigger(engine);
 
  const executeFunction = () => {
    const {functionName, params} = controller.state;
 
    if (functionName === 'log') {
      log(params);
    }
  };
 
  const log = (params: ExecuteTriggerParams) => {
    console.log('params: ', params);
  };
 
  const unsubscribe = controller.subscribe(() => executeFunction());
  return unsubscribe;
}

Associated Engines

The ExecuteTrigger controller is available in the following engine: