Skip to content

Commit d7121a7

Browse files
authored
Merge pull request #1 from autodatadirect/master
Merging master
2 parents f9b3e95 + 46897ed commit d7121a7

File tree

7 files changed

+540
-483
lines changed

7 files changed

+540
-483
lines changed

README.md

Lines changed: 72 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ When using Redux with Redux-Sagas, asynchronous options end up being fairly comp
88

99
Other libraries exist for handling asynchronous actions, usually by including middlewares. However, if you are already using the Redux-Saga middleware, it adds an extra layer of complication to add a new middleware on top of Redux-Sagas.
1010

11-
**Async-Ops** uses the Redux-Saga middleware to handle asynchronous operations, unifying all types of async calls under a small number of actionTypes which are handled by a single saga. Whenever you want to add a new asynchronous operation, all that you need to do is create an operation method using whatever technology you like (we like to use the Javascript `fetch` API for simplicity), register that operation, and fire the Async-Ops actions with the registered name and, boom.
11+
**Async-Ops** uses the Redux-Saga middleware to handle asynchronous operations, unifying all types of async calls under a small number of actionTypes which are handled by a single saga. Whenever you want to add a new asynchronous operation, all that you need to do is create an operation function using whatever technology you like (we like to use the Javascript `fetch` API for simplicity), register that operation, and fire the Async-Ops actions with the registered name and, boom.
1212

1313
## Usage
1414
Async-Ops is available on npm with the following command:
@@ -18,7 +18,7 @@ Async-Ops is available on npm with the following command:
1818

1919
## API
2020
### `register(name:String, operation:Function, mockOperation: Function) : Function`
21-
The `register` method registers an `operation` method and a `mockOperation` method under a given name. Operations must be registered prior to being used by the application.
21+
The `register` function registers an `operation` function and a `mockOperation` function under a given name. Operations must be registered prior to being used by the application.
2222

2323
#### Arguments
2424

@@ -40,7 +40,7 @@ register('fetchData', service, mock)
4040
```
4141

4242
### `callOperation(name:String, ...args) : Function`
43-
The `callOperation` method retrieves the `operation` registered at the provided name and then calls it, passing in `..args` to the called method.
43+
The `callOperation` function retrieves the `operation` registered at the provided name and then calls it, passing in `..args` to the called function.
4444

4545
#### Arguments
4646

@@ -50,7 +50,7 @@ The `callOperation` method retrieves the `operation` registered at the provided
5050

5151

5252
#### Return : Promise(result)
53-
`callOperation` returns the result of the previously registered `operation` method (or its `mockOperation`) after invoking it with the provided `...args`. If the `operation` result is not a `Promise`, it will be wrapped in a resolved `Promise`.
53+
`callOperation` returns the result of the previously registered `operation` function (or its `mockOperation`) after invoking it with the provided `...args`. If the `operation` result is not a `Promise`, it will be wrapped in a resolved `Promise`.
5454

5555
#### Example
5656
```javascript
@@ -66,34 +66,34 @@ const x = await callOperation('fetchData', 1) // x = 2
6666
```
6767

6868
### `enableMock() : Function`
69-
The `enableMock` method causes `callOperation` to use the `mockOperation` method rather than the `operation` method. The current mock status is set in the client's Local Storage.
69+
The `enableMock` function causes `callOperation` to use the `mockOperation` function rather than the `operation` function. The current mock status is set in the client's Local Storage.
7070

7171
### `disableMock() : Function`
72-
The `enableMock` method causes `callOperation` to use the `mockOperation` method rather than the `operation` method. The current mock status is set in the client's Local Storage.
72+
The `disableMock` function causes `callOperation` to use the `mockOperation` function rather than the `operation` function. The current mock status is set in the client's Local Storage.
7373

7474
### `actions : Object`
7575

76-
The `actions` object contains action creator methods which create the actions which are used by the Async-Ops `saga` to automatically run and process Async-Ops operations.
76+
The `actions` object contains action creator functions which create the actions which are used by the Async-Ops `saga` to automatically run and process Async-Ops operations.
7777

7878
### `actions.asyncOperationStart : Function(name:String | options:Object, ...args)`
7979

80-
The `asyncOperationStart` method creates an action which starts an async operation.
80+
The `asyncOperationStart` function creates an action which starts an async operation.
8181

8282
#### Arguments
8383

8484
**`name : String`** The name of the operation to be called.
8585

8686
**`options : Object`** An options object to use to call. The options object has the following possible properties:
8787
* *`name : String [required]`* The operation name.
88-
* *`channel : String [optional]`* A channel name to isolate operation call from other calls of the same operation.o
88+
* *`channel : String [optional]`* A channel name to isolate operation call from other calls of the same operation.
8989

9090
**`...args`** The arguments to be passed to the `operation` when it is called.
9191

9292
#### Return : Object
93-
The `asyncOperationStart` method returns a Redux-formatted action object with the following properties:
93+
The `asyncOperationStart` function returns a Redux-formatted action object with the following properties:
9494
* *`type : String`* This is always set to `'ASYNC_OPERATION'`
9595
* *`...args : Array[arg1, arg2, ...]`* an array of the args provided.
96-
* *`...options`* any other option values provided to the method
96+
* *`...options`* any other option values provided to the function
9797

9898
#### Example
9999
```javascript
@@ -119,14 +119,14 @@ The `saga` is a `Redux-Sagas` generator function which can be used with the Redu
119119
#### Example
120120
```javascript
121121
import { saga } from 'async-ops'
122-
import sageMiddleware from './sageMiddleware'
122+
import sagaMiddleware from './sagaMiddleware'
123123

124124
sagaMiddleware.run(saga)
125125
```
126126

127127
### `isAsyncOperation, isAsyncComplete, isAsyncFailure : Function(name:String, channel:String)`
128128

129-
These three methods are helper methods. They return a match function which takes an action Object and matches the actionType, name, and channel. This can used for Redux-Saga matching and React-Redux reducer matching.
129+
These three functions are helper functions. They return a match function which takes an action Object and matches the actionType, name, and channel. This can used for Redux-Saga matching and React-Redux reducer matching.
130130

131131
#### Arguments
132132

@@ -135,4 +135,62 @@ These three methods are helper methods. They return a match function which take
135135
**`channel : String [optional]`** A channel name to be matched.
136136

137137
#### Return : Function(action : Object)
138-
The method returned from the helper methods takes an action object and returns either `true` if the action matches the provided info or `false` if the action does not.
138+
The function returned from the helper functions takes an action object and returns either `true` if the action matches the provided info or `false` if the action does not.
139+
140+
### `reducer : Function`
141+
142+
The `reducer` is a Redux reducer function that can be added to an app's reducer to keep the store updated with the status about the latest async-ops calls. It must be put under the key 'asyncops' which can be imported from the async-ops package as `STORE_DOMAIN`.
143+
144+
#### Example
145+
```javascript
146+
import { combineReducers } from 'redux'
147+
import { reducer as asyncops } from 'async-ops'
148+
149+
const rootReducer = combineReducers({
150+
asyncops
151+
})
152+
```
153+
154+
### `loadingSelector : Function`
155+
156+
This selector function can be used to determine the loading state of an asynchronous operation.
157+
158+
#### Arguments
159+
160+
**`name : String [required]`** The name of the operation.
161+
162+
**`channel : String [optional]`** The name of the channel.
163+
164+
#### Return : Function(action : Object)
165+
The function returned from the selector functions takes a state object and returns either `true` if the asynchronous operation is currently loading or `false` if it is not.
166+
167+
#### Example
168+
```javascript
169+
import { selectors } from 'async-ops'
170+
171+
const mapStateToProps = state => ({
172+
testOpIsLoading: selectors.loadingSelector('testOp')(state)
173+
})
174+
```
175+
176+
### `errorSelector : Function`
177+
178+
This selector function can be used to retrieve error data from an asynchronous operation.
179+
180+
#### Arguments
181+
182+
**`name : String [required]`** The name of the operation.
183+
184+
**`channel : String [optional]`** The name of the channel.
185+
186+
#### Return : Function(action : Object)
187+
The function returned from the selector functions takes a state object and returns either null if the asynchronous operation did not error or an error object.
188+
189+
#### Example
190+
```javascript
191+
import { selectors } from 'async-ops'
192+
193+
const mapStateToProps = state => ({
194+
testOpError: selectors.errorSelector('testOp')(state)
195+
})
196+
```

0 commit comments

Comments
 (0)