Skip to main content

Core

Overview

The ServiceMessages class is a utility for managing and organizing service messages within different scopes. It provides functionalities to filter messages based on their scope, app-specific criteria, and timestamp/type sorting.

Constructor

constructor(_initial: ServiceMessage[])

Creates an instance of the ServiceMessages class.

  • Parameters:
    • _initial: An array of initial ServiceMessage objects.

Properties

messages$

  • Type: BehaviorSubject<ServiceMessage[]>
  • Description: BehaviorSubject that emits the current array of service messages.

appMessages$

  • Type: Observable<AppServiceMessage[]>
  • Description: Observable that emits an array of service messages with an "App" scope.

currentAppMessages$

  • Type: Observable<ServiceMessage[]>
  • Description: Observable that emits an array of service messages relevant to the current app or with a "Portal" scope.

portal$

  • Type: Observable<ServiceMessage[]>
  • Description: Observable that emits an array of service messages with a "Portal" scope.

currentAppKey$

  • Type: BehaviorSubject<string>
  • Description: BehaviorSubject that holds the current app key.

Methods

next(value: ServiceMessage[])

Updates the messages$ BehaviorSubject with new service messages.

  • Parameters:
    • value: An array of new ServiceMessage objects.

setCurrentApp(appKey: string)

Sets the current app key using the currentAppKey$ BehaviorSubject.

  • Parameters:
    • appKey: A string representing the new app key.

Getters

appMessages

  • Type: AppServiceMessage[]
  • Description: Returns an array of app-specific service messages by mapping the current service messages.

currentAppMessages

  • Type: ServiceMessage[]
  • Description: Returns an array of service messages relevant to the current app.

portalMessages

  • Type: ServiceMessage[]
  • Description: Returns an array of service messages with a "Portal" scope.

Private Methods

#appServiceMessageMapper(serviceMessages: ServiceMessage[]): AppServiceMessage[]

  • Description: Maps service messages to app-specific messages.

#sortMessages(serviceMessages: ServiceMessage[]): ServiceMessage[]

  • Description: Sorts service messages by timestamp and type.

#reduceAppServiceMessage(acc: Record<string, AppServiceMessage>, message: ServiceMessage): Record<string, AppServiceMessage>

  • Description: Reduces service messages to app-specific messages.

Usage Example

const initialMessages = [...]; // Initial array of ServiceMessage objects
const serviceMessages = new ServiceMessages(initialMessages);

This documentation provides a clear overview of the class, its properties, methods, and usage examples.