v0.8.1
Note: use v0.8.2+ since the custom rxjs observable in this commit was missing the catch operator, fixed in 0.8.2
Added new option processOptions
which influences the behavior of the process hook. It basically allows additional declaration to eliminate additional clutter in your code.
If you set the processOptions
object, you can further influence how process behaves streamlining your code.
processOptions.dispatchReturn
- if true, then process will use the returned value to dispatch. If you return a promise then it will use the resolve/reject values for dispatching. If you return an observable then it will use its values or error for dispatching. Returning an undefined, promise that resolves to undefined, or observable value of undefined will cause no dispatch. Default is false.processOptions.successType
- if set to an action type string or an action creator function it will use this to create the action from the dispatched value. If thesuccessType
was a string then it will create an action of this type and set the payload to the dispatched value. If it was an action creator function then it will pass the value to the action creator and then dispatch that. Default undefined.processOptions.failType
- if set to an action type string or an action creator function it will use this to create the action from the dispatched error or rejected promise value or errored observable similar to howsuccessType
works. IffailType
is not defined and an error is thrown or dispatched that does not itself have atype
(action type), then an UNHANDLED_LOGIC_ERROR will be dispatched with the error as the payload. Default undefined.
An example of using processOptions
:
const logic = createLogic({
type: FOO,
processOptions: {
dispatchReturn: true, // use my return for dispatch
successType: 'FOO_SUCCESS', // my action type for success
failType: 'FOO_ERROR', // my action type for failure
},
process({ getState, action }) {
// no need to dispatch when using dispatchReturn: true
// actions are created from the resolved or rejected promise
return axios.get('https://server/api/users')
.then(resp => resp.data.users); // select the data
}
}