Skip to content

Commit 8dc91ec

Browse files
committed
[CREATE] Action Types & Reducers
1 parent 2276af5 commit 8dc91ec

File tree

8 files changed

+69
-6
lines changed

8 files changed

+69
-6
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ npm install
116116
npm start
117117
```
118118

119+
3. To run the client
120+
121+
```
122+
cd client/
123+
npm start
124+
```
125+
119126
#### App
120127

121128
```

client/package-lock.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"react-dom": "^16.2.0",
1111
"react-router": "^4.2.0",
1212
"react-router-dom": "^4.2.2",
13-
"react-scripts": "1.1.1"
13+
"react-scripts": "1.1.1",
14+
"redux": "^3.7.2"
1415
},
1516
"scripts": {
1617
"start": "set PORT=3001 && react-scripts start",

client/src/constants/ActionTypes.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Constants are important - they describe what type of action is performed
3+
* within your app. Combined with the DevTools/logger, you can see how state
4+
* and subsequently your UI is being affected.
5+
*/
6+
7+
export const ADD_LIST = 'ADD_LIST';
8+
export const REMOVE_LIST = 'REMOVE_LIST';

client/src/reducers/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { combineReducers } from 'redux';
2+
import list from './list';
3+
4+
/**
5+
* combineReducers is important to understand. As your app might grow in size
6+
* and complexity, you will likely begin to split your reducers into separate
7+
* functions - with each one managing a separate slice of the state! This helper
8+
* function from 'redux' simply merges the reducers. Keep in mind we are using
9+
* the ES6 shorthand for property notation.
10+
*
11+
* If you're transitioning from Flux, you will notice we only use one store, but
12+
* instead of relying on multiple stores to manage diff parts of the state, we use
13+
* various reducers and combine them.
14+
*
15+
* More info: https://redux.js.org/api-reference/combinereducers
16+
*/
17+
const rootReducer = combineReducers({
18+
list, // you might be used to: list: list,
19+
});
20+
21+
export default rootReducer;

client/src/reducers/list.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ADD_LIST, REMOVE_LIST } from '../constants/ActionTypes';
2+
3+
export default function counter(state = 0, action) {
4+
switch (action.type) {
5+
case ADD_LIST:
6+
return state + 1;
7+
case REMOVE_LIST:
8+
return state - 1;
9+
default:
10+
return state;
11+
}
12+
}

server/boot/root.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module.exports = function(server) {
44
// Install a `/` route that returns server status
55
var router = server.loopback.Router();
6-
//router.get('/', server.loopback.status());
7-
router.get('/');
6+
router.get('/', server.loopback.status());
7+
//router.get('/');
88
server.use(router);
99
};

server/middleware.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@
4141
}
4242
},
4343
"files": {
44-
"loopback#static": {
45-
"params": "$!../client/build"
46-
}
44+
4745
},
4846
"final": {
4947
"loopback#urlNotFound": {}

0 commit comments

Comments
 (0)