blob: 03dcc9868a864414d399c1d7060b05ab65d74c26 [file] [log] [blame]
/********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
/**
* Every reducer module's default export is the reducer function itself. In
* addition, each module should export a type or interface that describes
* the state of the reducer plus any selector functions. The `* as`
* notation packages up all of the exports into a single object.
*/
import * as fromSettings from '@shared/store/reducers/settings.reducer';
import * as fromGridFailures from '@shared/store/reducers/grid-failures/grid-failures.reducer';
import { createFeatureSelector } from '@ngrx/store';
import { createSelector } from 'reselect';
/**
* We treat each reducer like a table in a database. This means
* our top level state interface is just a map of keys to inner state types.
*/
export interface State {
settings: fromSettings.State;
}
export interface GridFailureState {
gridFailures: fromGridFailures.State;
}
/**
* Because metareducers take a reducer function and return a new reducer,
* we can use our compose helper to chain them together. Here we are
* using combineReducers to make our top level reducer, and then
* wrapping that in storeLogger. Remember that compose applies
* the result from right to left.
*/
export const reducers = {
settings: fromSettings.reducer,
};
export const gridFailureReducers = {
gridFailures: fromGridFailures.reducer,
};
/**
* Every reducer module exports selector functions, however child reducers
* have no knowledge of the overall state tree. To make them useable, we
* need to make new selectors that wrap them.
*/
/**
* Settings store functions
*/
export const getSettingsState = (state: State) => state.settings;
export const getSelectedLanguage = createSelector(getSettingsState, fromSettings.getSelectedLanguage);
export const getSelectedCulture = createSelector(getSettingsState, fromSettings.getSelectedCulture);
export const getAvailableLanguages = createSelector(getSettingsState, fromSettings.getAvailableLanguages);
/**
* Settings store functions
*/
export const getUser = createSelector(getSettingsState, fromSettings.getUser);
/**
* GridFailures store functions
*/
export const selectGridFailuresState = createFeatureSelector<GridFailureState>('grid-failure');
// GridFailures list
export const selectGridFailures = createSelector(selectGridFailuresState, (state: GridFailureState) => state.gridFailures);
export const getGridFailuresLoaded = createSelector(selectGridFailures, fromGridFailures.getLoaded);
export const getGridFailuresLoading = createSelector(selectGridFailures, fromGridFailures.getLoading);
export const getGridFailuresFailed = createSelector(selectGridFailures, fromGridFailures.getFailed);
export const getGridFailuresData = createSelector(selectGridFailures, fromGridFailures.getData);