All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ducks.alerts.selectors.ts Maven / Gradle / Ivy

The newest version!
import { createSelector } from '@reduxjs/toolkit'

import { State as ReduxState } from '../State'
import { EMPTY_ARRAY } from '../../utils/emptyTypes'

import { Key } from './constants'

/**
 * Селектор алертов
 */
const alertsSelector = (store: ReduxState) => store.alerts

/**
 * Селектор айтемов по ключу
 */
export const alertsByKeySelector = (key: Key) => createSelector(
    alertsSelector,
    alertsStore => alertsStore[key] || EMPTY_ARRAY,
)

/**
 * Селектор по ключу и индексу алерта
 */
export const alertByIdAndKeySelector = (key: Key, index: number) => createSelector(
    alertsByKeySelector(key),
    alerts => (alerts.length ? alerts[index] : null),
)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy