UNPKG

@mui/x-tree-view

Version:

The community edition of the MUI X Tree View components.

27 lines (24 loc) 1.54 kB
import { createSelector } from "../../utils/selectors.js"; const selectorLazyLoading = state => state.lazyLoading; const selectorLazyLoadingOptional = state => state.lazyLoading; export const selectorDataSourceState = createSelector([selectorLazyLoading], lazyLoading => lazyLoading.dataSource); /** * Check if lazy loading is enabled. * @param {TreeViewState<[UseTreeViewLazyLoadingSignature]>} state The state of the tree view. * @returns {boolean} True if lazy loading is enabled, false if it isn't. */ export const selectorIsLazyLoadingEnabled = createSelector([selectorLazyLoadingOptional], lazyLoading => !!lazyLoading?.enabled); /** * Get the loading state for a tree item. * @param {TreeViewState<[UseTreeViewLazyLoadingSignature]>} state The state of the tree view. * @param {TreeViewItemId} itemId The id of the item to get the loading state of. * @returns {boolean} The loading state for the Tree Item. */ export const selectorIsItemLoading = createSelector([selectorDataSourceState, (_, itemId) => itemId], (dataSourceState, itemId) => dataSourceState.loading[itemId] || false); /** * Get the error for a tree item. * @param {TreeViewState<[UseTreeViewLazyLoadingSignature]>} state The state of the tree view. * @param {TreeViewItemId} itemId The id of the item to get the error for. * @returns {boolean} The error for the Tree Item. */ export const selectorGetTreeItemError = createSelector([selectorDataSourceState, (_, itemId) => itemId], (dataSourceState, itemId) => dataSourceState.errors[itemId] || null);