Skip to main content

Selection History Service

Overview

The SelectionHistoryService class is responsible for managing the selection history. It keeps track of the history of selected articles and provides methods to navigate through the history. The service also emits events when the selection history changes. This service is used by the Drawer.

getCurrentSelectionIndex()

Retrieves the index of the current selection.

public getCurrentSelectionIndex(): number

Returns:

  • number: The index of the current selection, which is the last element in the history array.

Usage Example:

const currentIndex = selectionHistoryService.getCurrentSelectionIndex();
console.log(currentIndex);

getSelection()

Retrieves an article from the selection history at the specified index.

public getSelection(index: number): Article | undefined
ParameterTypeDescription
indexnumberThe index of the article to retrieve.

Returns:

  • Article | undefined: The article at the specified index, or undefined if the index is out of bounds.

Usage Example:

const article = selectionHistoryService.getSelection(0);
console.log(article);

getHistoryLength()

Retrieves the length of the history array.

public getHistoryLength(): number

Returns:

  • number: The number of entries in the history.

Usage Example:

const historyLength = selectionHistoryService.getHistoryLength();
console.log(historyLength);

clearHistory()

Clears the selection history and resets the current article selection.

public clearHistory(): void

Usage Example:

selectionHistoryService.clearHistory();

back()

Navigates back in the selection history.

public back(): Article | undefined

Returns:

  • Article | undefined: The last article in the history, or undefined if the history is empty.

Usage Example:

const previousArticle = selectionHistoryService.back();
console.log(previousArticle);