Skip to content

Commit

Permalink
feat: support dispatch action in onError hook
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Oct 9, 2016
1 parent 6fb6fa6 commit 7f2575a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/createDva.js
Expand Up @@ -95,7 +95,7 @@ export default function createDva(createOpts) {
const onErrorWrapper = (err) => {
if (err) {
if (typeof err === 'string') err = new Error(err);
onError(err);
onError(err, app._store.dispatch);
}
};

Expand Down
7 changes: 6 additions & 1 deletion test/effects-test.js
Expand Up @@ -105,13 +105,17 @@ describe('effects', () => {
it('onError', () => {
const errors = [];
const app = dva({
onError: (error) => {
onError: (error, dispatch) => {
errors.push(error.message);
dispatch({ type: 'count/add' });
}
});
app.model({
namespace: 'count',
state: 0,
reducers: {
add(state) { return state + 1; },
},
effects: {
*addDelay() {
throw new Error('effect error');
Expand All @@ -122,6 +126,7 @@ describe('effects', () => {
app.start();
app._store.dispatch({ type: 'count/addDelay' });
expect(errors).toEqual(['effect error']);
expect(app._store.getState().count).toEqual(1);
});

it('type: takeLatest', (done) => {
Expand Down

0 comments on commit 7f2575a

Please sign in to comment.