Skip to content

Commit c848866

Browse files
author
Robert S
committed
update comments
1 parent 4e352c9 commit c848866

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,27 @@
66

77
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
88

9+
### Install Packages
10+
11+
#### `yarn` or `npm install`
12+
913
## Available Scripts
1014

1115
In the project directory, you can run:
1216

13-
### `yarn start`
17+
#### `yarn start` or `npm start`
1418

1519
Runs the app in the development mode.<br>
1620
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
1721

1822
The page will reload if you make edits.<br>
1923
You will also see any lint errors in the console.
2024

21-
### `yarn generate`
25+
#### `yarn generate` or `npm generate`
2226

2327
Scaffolding tool, see [generate-template-files](https://github.com/codeBelt/generate-template-files#readme). Check the `tools/templates` directory for existing templates.
2428

25-
### `yarn build`
29+
#### `yarn build` or `npm build`
2630

2731
Builds the app for production to the `build` folder.<br>
2832
It correctly bundles React in production mode and optimizes the build for the best performance.

src/stores/error/ErrorReducer.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ export default class ErrorReducer {
1313
const { type, error, payload } = action;
1414

1515
/*
16-
* Removes a specific error by it's id.
16+
* Removes an HttpErrorResponseModel by it's id that is in the action payload.
1717
*/
1818
if (type === ErrorAction.REMOVE) {
19-
// Create a new state without the error that has the same id as the payload
19+
// Create a new state without the error that has the same id as the payload.
2020
return Object.entries(state).reduce((newState: object, [key, value]: [string, HttpErrorResponseModel]) => {
2121
if (value.id !== payload) {
2222
newState[key] = value;
@@ -27,35 +27,47 @@ export default class ErrorReducer {
2727
}
2828

2929
/*
30-
* Removes all the stored errors.
30+
* Removes all errors by returning the initial state which is an empty object.
3131
*/
3232
if (type === ErrorAction.CLEAR_ALL) {
3333
return ErrorReducer.initialState;
3434
}
3535

3636
/*
37-
* If the action type has the key word '_FINISHED' then the start action is complete
37+
* True if the action type has the key word '_FINISHED' then the action is finished.
3838
*/
39-
const isFinishedRequestType: boolean = type.includes('_FINISHED');
39+
const isFinishedRequestType = type.includes('_FINISHED');
4040
/*
41-
* If the action type has the key word 'REQUEST_' and not '_FINISHED' then we
42-
* want to remove the old error because there is a new request happening.
41+
* True if the action type has the key word 'REQUEST_' and not '_FINISHED'.
4342
*/
44-
const isStartRequestType: boolean = type.includes('REQUEST_') && !isFinishedRequestType;
43+
const isStartRequestType = type.includes('REQUEST_') && !isFinishedRequestType;
4544

45+
/*
46+
* If an action is started we want to remove any old errors because there is a new action has been re-dispatched.
47+
*/
4648
if (isStartRequestType) {
47-
// remove the finished type that is associated with the start type because the start action has been re-dispatched
49+
// Using ES7 Object Rest Spread operator to omit properties from an object.
4850
const { [`${type}_FINISHED`]: value, ...stateWithoutFinishedType } = state;
4951

5052
return stateWithoutFinishedType;
5153
}
5254

55+
/*
56+
* True if the action is finished and the error property is true.
57+
*/
5358
const isError: boolean = isFinishedRequestType && Boolean(error);
5459

60+
/*
61+
* For any start and finished actions that don't have errors we return the current state.
62+
*/
5563
if (isError === false) {
5664
return state;
5765
}
5866

67+
/*
68+
* At this point the "type" will be a finished action type (e.g. "SomeAction.REQUEST_*_FINISHED").
69+
* The payload will be a HttpErrorResponseModel.
70+
*/
5971
return {
6072
...state,
6173
[type]: payload,

src/stores/requesting/RequestingReducer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export default class RequestingReducer {
1515
return state;
1616
}
1717

18-
// Remove the string '_FINISHED' from the action type so we can use it as the key on the state.
19-
const [requestName] = action.type.split('_FINISHED');
18+
// Remove the string '_FINISHED' from the action type so we can use the first part as the key on the state.
19+
const requestName: string = action.type.replace('_FINISHED', '');
2020
// If the action type includes '_FINISHED'. The boolean value will be false. Otherwise we
2121
// assume it is a starting request and will be set to true.
2222
const isFinishedRequestType: boolean = action.type.includes('_FINISHED');

0 commit comments

Comments
 (0)