Skip to content

Commit 86520e2

Browse files
committed
Improve the README as requsted in issue #1
1 parent da6ae64 commit 86520e2

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

README.md

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,51 @@ This is an attempt to add asynchronous swagger api calls to redux. It works by d
88

99
## Installation
1010
note: This module requires [redux-thunk](https://github.com/gaearon/redux-thunk)
11+
Github:
12+
```
13+
npm install --save github:noh4ck/redux-swagger-client
14+
```
1115

16+
Package pending:
1217
```
1318
npm install --save redux-swagger-client
1419
```
1520

16-
Then, to enable Redux Swagger-client, use [`applyMiddleware()`](http://redux.js.org/docs/api/applyMiddleware.html):
21+
To enable Redux Swagger-client, use [`applyMiddleware()`](http://redux.js.org/docs/api/applyMiddleware.html):
1722

1823
```js
19-
import { createStore, applyMiddleware } from 'redux';
20-
import swaggerClient from 'redux-swagger-client';
21-
import rootReducer from './reducers/index';
24+
import { createStore, applyMiddleware } from 'redux'
25+
import swaggerClient from 'redux-swagger-client'
26+
import thunk from 'redux-thunk'
2227

2328
const store = createStore(
2429
rootReducer,
25-
applyMiddleware(swaggerClient({url:'http://petstore.swagger.io/v2/swagger.json'})
30+
applyMiddleware([
31+
thunk,
32+
swaggerClient({url:'http://petstore.swagger.io/v2/swagger.json'})
33+
])
2634
);
2735
```
2836

2937
## Usage
3038
```js
31-
function fetchPets() {
32-
return (dispatch) => {
33-
dispatch({
34-
type: "FETCH_PETS",
35-
swagger: (s) => {
36-
s.pet.findPetsByStatus({status: 'available'},
37-
(pets) => { dispatch({
38-
type: "FETCH_PETS_SUCCESS",
39-
payload: pets
40-
})}
41-
)
42-
}
43-
})
44-
}
39+
var fetchPets = () => (dsp) => {
40+
dsp({
41+
type: "FETCH_PETS",
42+
swagger: (api) => {
43+
api.pet.findPetsByStatus(
44+
{status: 'available'},
45+
(pets) => dsp({
46+
type: "FETCH_PETS_SUCCESS",
47+
payload: pets
48+
}),
49+
(error) => dsp({
50+
type: "FETCH_PETS_FAILED",
51+
payload: error
52+
})
53+
)
54+
}
55+
})
4556
}
4657

4758
store.dispatch(fetchPets())

0 commit comments

Comments
 (0)