Skip to content

Commit 19836d0

Browse files
authored
Merge pull request #19 from jmeas/update-lib-versions
Update lib versions
2 parents 5dca8a5 + d0b2706 commit 19836d0

File tree

5 files changed

+48
-155
lines changed

5 files changed

+48
-155
lines changed

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6-
"history": "^4.6.3",
76
"lodash": "^4.17.4",
87
"react": "^16.0.0",
98
"react-dom": "^16.0.0",
109
"react-redux": "^5.0.5",
11-
"react-router": "^4.1.1",
1210
"react-router-dom": "^4.1.1",
1311
"react-scripts": "1.0.10",
1412
"redux": "^3.7.1",
15-
"redux-resource": "^2.2.0",
16-
"redux-resource-plugins": "^2.0.0",
17-
"redux-resource-xhr": "^2.0.0",
13+
"redux-resource": "^2.4.0",
14+
"redux-resource-plugins": "^2.1.0",
15+
"redux-resource-xhr": "^2.2.0",
1816
"redux-thunk": "^2.2.0",
1917
"xhr": "^2.4.0"
2018
},

src/components/App.test.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/index.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
33
import { Provider } from 'react-redux';
4-
import { Router } from 'react-router';
5-
import createBrowserHistory from 'history/createBrowserHistory';
6-
import { Route, Switch } from 'react-router-dom';
4+
import { BrowserRouter, Route, Switch } from 'react-router-dom';
75
import './index.css';
86
import App from './components/App';
97
import Gists from './components/Gists';
108
import Gist from './components/Gist';
119
import CreateGist from './components/CreateGist';
12-
import registerServiceWorker from './registerServiceWorker';
1310
import store from './state/store';
1411

15-
const history = createBrowserHistory();
16-
1712
ReactDOM.render((
1813
<Provider store={store}>
19-
<Router history={history}>
14+
<BrowserRouter>
2015
<Route path="/" render={({ location }) => (
2116
<App location={location}>
2217
<Switch>
@@ -26,7 +21,6 @@ ReactDOM.render((
2621
</Switch>
2722
</App>
2823
)}/>
29-
</Router>
24+
</BrowserRouter>
3025
</Provider>
3126
), document.getElementById('root'));
32-
registerServiceWorker();

src/registerServiceWorker.js

Lines changed: 0 additions & 108 deletions
This file was deleted.

src/state/gists/action-creators.js

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
import { actionTypes } from 'redux-resource';
2-
import {
3-
createResources, readResources, updateResources, deleteResources
4-
} from 'redux-resource-xhr';
2+
import { crudRequest } from 'redux-resource-xhr';
53
import headers from '../../utils/headers';
64

5+
// This file heavily leverages the Redux Resource XHR library. To learn
6+
// more about its API, refer to the documentation:
7+
// https://redux-resource.js.org/docs/extras/redux-resource-xhr.html
8+
79
// The Redux Resource XHR library only exports bulk actions, so we use this
810
// function to turn single-resource responses from the server into arrays.
9-
function transformSingular(body) {
11+
function singleResourceToArray(body) {
1012
return [body];
1113
}
1214

1315
export function createGist(gist) {
1416
const xhrOptions = {
17+
method: 'POST',
1518
url: 'https://api.github.com/gists',
1619
json: true,
1720
body: gist,
1821
headers
1922
};
2023

21-
return dispatch => createResources({
22-
resourceName: 'gists',
23-
request: 'createGist',
24-
list: 'createdGists',
25-
transformData: transformSingular,
24+
return dispatch => crudRequest('create', {
25+
actionDefaults: {
26+
resourceName: 'gists',
27+
request: 'createGist',
28+
list: 'createdGists',
29+
},
30+
transformData: singleResourceToArray,
2631
xhrOptions,
2732
dispatch
2833
});
@@ -38,49 +43,58 @@ export function resetCreateGistStatus() {
3843

3944
export function readGist(gistId) {
4045
const xhrOptions = {
46+
method: 'GET',
4147
url: `https://api.github.com/gists/${gistId}`,
4248
json: true,
4349
headers
4450
};
4551

46-
return dispatch => readResources({
47-
resourceName: 'gists',
48-
resources: [gistId],
49-
transformData: transformSingular,
52+
return dispatch => crudRequest('read', {
53+
actionDefaults: {
54+
resourceName: 'gists',
55+
resources: [gistId],
56+
},
57+
transformData: singleResourceToArray,
5058
xhrOptions,
5159
dispatch
5260
});
5361
}
5462

5563
export function readManyUsersGists(username) {
5664
const xhrOptions = {
65+
method: 'GET',
5766
url: `https://api.github.com/users/${username}/gists`,
5867
json: true,
5968
headers
6069
};
6170

62-
return dispatch => readResources({
63-
resourceName: 'gists',
64-
request: 'getUsersGists',
65-
list: 'usersGists',
66-
mergeListIds: false,
71+
return dispatch => crudRequest('read', {
72+
actionDefaults: {
73+
resourceName: 'gists',
74+
request: 'getUsersGists',
75+
list: 'usersGists',
76+
mergeListIds: false,
77+
},
6778
xhrOptions,
6879
dispatch
6980
});
7081
}
7182

7283
export function updateGist(gistId, gist) {
7384
const xhrOptions = {
85+
method: 'PATCH',
7486
url: `https://api.github.com/gists/${gistId}`,
7587
json: true,
7688
body: gist,
7789
headers
7890
};
7991

80-
return dispatch => updateResources({
81-
resourceName: 'gists',
82-
resources: [gistId],
83-
transformData: transformSingular,
92+
return dispatch => crudRequest('update', {
93+
actionDefaults: {
94+
resourceName: 'gists',
95+
resources: [gistId],
96+
},
97+
transformData: singleResourceToArray,
8498
xhrOptions,
8599
dispatch
86100
});
@@ -96,13 +110,16 @@ export function resetUpdateGistStatus(gistId) {
96110

97111
export function deleteGist(gistId) {
98112
const xhrOptions = {
113+
method: 'DELETE',
99114
url: `https://api.github.com/gists/${gistId}`,
100115
headers
101116
};
102117

103-
return dispatch => deleteResources({
104-
resourceName: 'gists',
105-
resources: [gistId],
118+
return dispatch => crudRequest('delete', {
119+
actionDefaults: {
120+
resourceName: 'gists',
121+
resources: [gistId],
122+
},
106123
xhrOptions,
107124
dispatch
108125
});

0 commit comments

Comments
 (0)