THIS IS ARCHIVED DOCUMENTATION

(Deprecated) HistoryManager

The HistoryManager controller is in charge of allowing navigating back and forward in the search interface history.

Methods

back

Move backward in the interface history.

Returns Promise<void>: A promise that resolves when the previous state has been restored.

forward

Move forward in the interface history.

Returns Promise<void>: A promise that resolves when the next state has been restored.

subscribe

Adds a callback that will be called on state change.

Parameters

  • listener: () ⇒ void

    A callback to be invoked on state change.

Returns Unsubscribe: An unsubscribe function to remove the listener.

Attributes

state

The state relevant to the HistoryManager controller.

Initialize

buildHistoryManager

Creates a HistoryManager controller instance.

Parameters

  • engine: Engine<object>

    The headless engine.

Returns HistoryManager

Unsubscribe

Call signatures

  • (): void

Example Implementation

history-manager.fn.tsx

import {useEffect, useState, FunctionComponent} from 'react';
import {HistoryManager as HeadlessHistoryManager} from '@coveo/headless';
 
interface HistoryManagerProps {
  controller: HeadlessHistoryManager;
}
 
export const HistoryManager: FunctionComponent<HistoryManagerProps> = (
  props
) => {
  const {controller} = props;
  const [state, setState] = useState(controller.state);
 
  useEffect(() => controller.subscribe(() => setState(controller.state)), []);
 
  return (
    <div>
      <button
        disabled={state.past.length === 0}
        onClick={() => controller.back()}
      >
        Back
      </button>
      <button
        disabled={state.future.length === 0}
        onClick={() => controller.forward()}
      >
        Forward
      </button>
    </div>
  );
};
 
// usage
 
/**
 * ```tsx
 * const controller = buildHistoryManager(engine);
 *
 * <History controller={controller} />;
 * ```
 */