E.W.O. Next / All files / src/client selector.ts

84.21% Statements 16/19
62.5% Branches 5/8
100% Functions 5/5
81.25% Lines 13/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43            3x     16x 12x 4x   3x       12x 9x 9x                 3x       3x     4x 2x     2x      
/**
 * @module Client.Selector
 * Selectors for Redux
 */
 
import { CharacterFrontend, ViewFrontend } from '@models';
import { createSelector } from 'reselect';
import { IStateFrontend } from './reducers';
 
export const getMat = (state: IStateFrontend) => state.selectedCharacter;
export const getCharacters = (state: IStateFrontend) => state.characters;
export const getView = (state: IStateFrontend) => state.views;
 
export const getSelectedCharacter = createSelector(
  [getCharacters, getMat],
  (characters: Record<string, CharacterFrontend>, mat): CharacterFrontend => {
 
    if (mat !== undefined) {
      Eif (characters[mat] !== undefined) {
        return characters[mat];
      }
 
      const firstMat = Object.keys(characters);
      if (firstMat.length > 0) {
        return characters[firstMat[0]];
      }
    }
 
    return;
  },
);
 
export const getSelectedView = createSelector(
  [getView, getMat],
  (views: { [key: string]: ViewFrontend }, mat): ViewFrontend => {
    if (views[mat] !== undefined) {
      return views[mat];
    }
 
    return null;
  },
);