Skip to content

Commit c30248b

Browse files
author
Robert S
committed
ErrorSelector jsDocs
1 parent ba3887b commit c30248b

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

src/selectors/error/ErrorSelector.js

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
import { createSelector } from 'reselect';
22

3+
/**
4+
* @typedef {Object.<string, HttpErrorResponseModel>} IErrorState
5+
*/
6+
7+
/**
8+
* ErrorSelector
9+
*
10+
* @static
11+
*/
312
export class ErrorSelector {
13+
/**
14+
* Creates a new object with the key being the finished action type
15+
* (e.g. "SomeAction.REQUEST_*_FINISHED") and the value being the
16+
* HttpErrorResponseModel.
17+
*
18+
* @param {IErrorState} errorState
19+
* @param {string[]} actionTypes
20+
* @returns {IErrorState}
21+
* @static
22+
*/
423
static selectRawErrors(errorState, actionTypes) {
524
return actionTypes.reduce((partialState, actionType) => {
625
if (errorState[actionType]) {
@@ -11,12 +30,19 @@ export class ErrorSelector {
1130
}, {});
1231
}
1332

33+
/**
34+
* Finds any errors matching the array of actionTypes and combines all error
35+
* messages in to a single string.
36+
*
37+
* @param {IErrorState} errorState
38+
* @param {string[]} actionTypes
39+
* @returns {string}
40+
* @static
41+
*/
1442
static selectErrorText(errorState, actionTypes) {
15-
const partialErrorState = ErrorSelector.selectRawErrors(errorState, actionTypes);
16-
1743
const errorList = actionTypes.reduce((errorMessages, actionType) => {
18-
if (partialErrorState[actionType]) {
19-
const { message, errors } = partialErrorState[actionType];
44+
if (errorState[actionType]) {
45+
const { message, errors } = errorState[actionType];
2046
const arrayOfErrors = errors.length ? errors : [message];
2147

2248
return errorMessages.concat(arrayOfErrors);
@@ -28,6 +54,14 @@ export class ErrorSelector {
2854
return errorList.join(', ');
2955
}
3056

57+
/**
58+
* Returns true or false if there are errors found matching the array of actionTypes.
59+
*
60+
* @param {IErrorState} errorState
61+
* @param {string[]} actionTypes
62+
* @returns {boolean}
63+
* @static
64+
*/
3165
static hasErrors(errorState, actionTypes) {
3266
return actionTypes.map((actionType) => errorState[actionType]).filter(Boolean).length > 0;
3367
}

0 commit comments

Comments
 (0)