Skip to content

Commit 048d902

Browse files
author
Onoufrios Malikkides
committed
Added mock api data
1 parent 80f1388 commit 048d902

File tree

4 files changed

+42
-15
lines changed

4 files changed

+42
-15
lines changed

README.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# State management with Redux
22

3-
This project serves as a guide to structure Redux for a react app. The goal is to setup Redux in such way that it will cover most (over 90%) of your api needs.
3+
This project serves as a guide to structure Redux for a react app. The goal is to setup Redux in such way that it will cover most (over 90%) of our api needs.
44

55
> #### _Like this guide?_ **Show your support by giving a :star:**
66
7-
**Note:** This code is nearly complete (See [Coming soon](#coming-soon)). It is functional and can be used as is or serve as inspiration. Some actions (delete, create) for multiple entities might not work as expected yet.
8-
97
---
108

119
## Table of Contents
@@ -110,13 +108,8 @@ See `src/components/Main/index.js` for the full example.
110108

111109
TODO:
112110

113-
1. Fix + make uniform create, delete, toggle for multiple entities
114-
2. Finish writing unit tests
115-
3. Write examples for cursor/page based read
116-
4. Add caching
117-
5. Add optimistic updates
118-
6. Allow for rxjs/saga replacement
119-
7. Finish writing documentation
120-
8. Publish to npm (I plan to turn this into a package that everyone can use )
111+
1. Add examples for cursor/page based read
112+
2. Add example for caching / optimistic updates
113+
3. Publish to npm (I plan to turn this into a package that everyone can use )
121114

122115
[⇧ back to top](#table-of-contents)

package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
{
2-
"name": "state",
3-
"version": "0.1.0",
4-
"private": true,
2+
"name": "redux-setup-guide",
3+
"version": "0.2.0",
4+
"description": "Guide on how to setup Redux for a react application",
5+
"license": "MIT",
6+
"author": "Onoufrios Malikkides",
7+
"keywords": [
8+
"redux",
9+
"react",
10+
"state",
11+
"guide"
12+
],
513
"dependencies": {
614
"antd": "^3.11.2",
715
"axios": "^0.18.0",

src/index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,32 @@ import { Provider } from 'react-redux';
44
import AppLayout from './components/Layout';
55
import * as serviceWorker from './serviceWorker';
66
import setupStore from './redux';
7+
import axios from 'axios';
8+
import MockAdapter from 'axios-mock-adapter';
9+
10+
// Mock api calls
11+
const axiosMock = new MockAdapter(axios, { delayResponse: 500 });
12+
axiosMock.onGet('http://localhost:8000/user/1').reply(200, {
13+
id: 1,
14+
name: 'John',
15+
posts: [{ id: 1, tags: [{ id: 1, name: 'important' }] }],
16+
});
17+
axiosMock.onGet('http://localhost:8000/tag').reply(200, [
18+
{ id: 1, name: 'important' },
19+
{ id: 2, name: 'serious' },
20+
{ id: 3, name: 'ready' },
21+
]);
22+
axiosMock.onPut('http://localhost:8000/user/1').reply(200, {
23+
id: 1,
24+
name: 'James',
25+
});
26+
axiosMock.onPost('http://localhost:8000/post').reply(200, {
27+
id: 20,
28+
text: 'My newly created post',
29+
tags: [],
30+
});
31+
axiosMock.onDelete('http://localhost:8000/post/1').reply(200,{});
32+
733

834
const store = setupStore({}, { debug: true });
935

src/react-redux/Entity/Create/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const mapStateToProps = (state, ownProps) => ({
2121
});
2222

2323
const mapDispatchToProps = (dispatch, ownProps) => ({
24-
create(body, options) {
24+
create(body, options = {}) {
2525
const enhancedOptions = {
2626
...options,
2727
onSuccess: () => {

0 commit comments

Comments
 (0)