Skip to content

Commit

Permalink
add reduxFormFallback flag, pass payload to success if flag is falsy
Browse files Browse the repository at this point in the history
  • Loading branch information
afitiskin committed Oct 16, 2017
1 parent 4df8600 commit ca31f17
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redux-saga-routines",
"version": "1.1.4",
"version": "1.1.5",
"description": "Routines for redux-saga also useful with redux-form",
"keywords": [
"redux",
Expand Down
3 changes: 2 additions & 1 deletion src/createRoutine.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PROMISE_ACTION } from './constants';

const identity = i => i;

export default function createRoutine(routineName = '', payloadCreator = identity) {
export default function createRoutine(routineName = '', payloadCreator = identity, reduxFormFallback = true) {
if (typeof routineName !== 'string') {
throw new Error('Invalid routine name, it should be a string');
}
Expand All @@ -29,6 +29,7 @@ export default function createRoutine(routineName = '', payloadCreator = identit
data,
params: routineParams,
defer: { resolve, reject },
reduxFormFallback,
},
}));
};
Expand Down
6 changes: 3 additions & 3 deletions src/routinesWatcherSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PROMISE_ACTION } from './constants'
const getPayload = (data) => (data && data.payload) || data;

export function* handlePromiseAction(action) {
const { data, params, defer: { resolve, reject } } = action.payload;
const { data, params, defer: { resolve, reject }, reduxFormFallback } = action.payload;

const [ {success, failure} ] = yield all([
race({
Expand All @@ -13,9 +13,9 @@ export function* handlePromiseAction(action) {
}),
put(params.trigger(data)),
]);

if (success) {
yield call(resolve);
yield reduxFormFallback ? call(resolve) : call(resolve, getPayload(success));
} else {
yield call(reject, getPayload(failure));
}
Expand Down

0 comments on commit ca31f17

Please sign in to comment.