Skip to content
This repository has been archived by the owner on Jan 18, 2021. It is now read-only.

Commit

Permalink
feat: 🎸 unfoldSaga return success data
Browse files Browse the repository at this point in the history
  • Loading branch information
manhhailua committed Sep 28, 2019
1 parent fd31ecc commit 2f89269
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,11 @@ export function* unfoldSaga(
{ handler, key }: UnfoldSagaHandlerType,
{ onBeginning = noop, onFailure = noop, onFinish = noop, onSuccess = noop }: UnfoldSagaCallbacksType = {},
): any {
let data;

try {
yield put({ type: createActionTypeOnBeginning(key) });
yield call(onBeginning);
let data;
if (['GeneratorFunction', 'AsyncGeneratorFunction'].includes(handler.constructor.name)) {
data = yield* handler();
} else {
Expand All @@ -181,6 +182,8 @@ export function* unfoldSaga(
yield put({ type: createActionTypeOnFinish(key) });
yield call(onFinish);
}

return data;
}

export default {
Expand Down
1 change: 1 addition & 0 deletions test/unfoldSagaAsync.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ describe('unfoldSaga for async handler', () => {
test('should end', () => {
result = generator.next();
expect(result.done).toBe(true);
expect(result.value).toBe(fakeResult);
});
});

Expand Down
1 change: 1 addition & 0 deletions test/unfoldSagaGenerator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ describe('unfoldSaga for generator handler', () => {
test('should end', () => {
result = generator.next();
expect(result.done).toBe(true);
expect(result.value).toBe(fakeResult);
});
});

Expand Down

0 comments on commit 2f89269

Please sign in to comment.