Skip to content
This repository was archived by the owner on Oct 19, 2019. It is now read-only.

Commit c88777d

Browse files
committed
fix: loading state error when epic error
1 parent ec37378 commit c88777d

4 files changed

Lines changed: 66 additions & 3 deletions

File tree

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface API {
99
onEpicStart$: Observable<any>,
1010
onEpicEnd$: Observable<any>,
1111
onEpicCancel$: Observable<any>,
12+
onEpicError$: Observable<any>,
1213
}
1314

1415
export type Plugin = (api: API) => void;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"rxjs": "^6.0.0-0"
4141
},
4242
"devDependencies": {
43-
"@rxloop/core": "^0.8.1",
43+
"@rxloop/core": "^0.9.0",
4444
"babel-cli": "^6.26.0",
4545
"babel-core": "^6.26.2",
4646
"babel-jest": "^22.4.3",

src/index.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export default function loading(
33
name: 'loading',
44
}
55
) {
6-
return function init({ onModel$, onEpicStart$, onEpicEnd$, onEpicCancel$ }) {
6+
return function init({ onModel$, onEpicStart$, onEpicEnd$, onEpicCancel$, onEpicError$ }) {
77
const _model = {
88
name: config.name,
99
state: {
@@ -136,6 +136,25 @@ export default function loading(
136136
loading: -1,
137137
});
138138
});
139+
140+
onEpicError$
141+
.subscribe(data => {
142+
// this.dispatch({
143+
// type: 'loading/globalLoading',
144+
// loading: -1,
145+
// });
146+
// this.dispatch({
147+
// type: 'loading/modelLoading',
148+
// model: data.model,
149+
// loading: -1,
150+
// });
151+
this.dispatch({
152+
epic: data.epic,
153+
type: 'loading/epicLoading',
154+
model: data.model,
155+
loading: -1,
156+
});
157+
});
139158

140159
onEpicCancel$
141160
.subscribe(data => {

test/index.spec.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import rxloop from '@rxloop/core';
22
import loading from '../src/';
3-
import { delay, mapTo } from "rxjs/operators";
3+
import { delay, mapTo, map } from "rxjs/operators";
44

55
const app1 = rxloop();
66

@@ -101,3 +101,46 @@ describe('test epic loading', () => {
101101
}, 3000);
102102
});
103103
});
104+
105+
describe('test epic loading when error', () => {
106+
const app = rxloop({
107+
plugins: [ loading() ],
108+
});
109+
app.model({
110+
name: 'test',
111+
state: {},
112+
reducers: {
113+
add(state) {
114+
return state;
115+
}
116+
},
117+
epics: {
118+
getDataError(action$) {
119+
return action$.pipe(
120+
delay(2000),
121+
map(() => {
122+
throw 'boom!';
123+
}),
124+
);
125+
},
126+
},
127+
});
128+
129+
app.stream('loading').subscribe();
130+
131+
test('loading test', (done) => {
132+
app.dispatch({ type: 'test/getDataError' });
133+
setTimeout(() => {
134+
expect(app.getState('loading')).toEqual({
135+
global: 0,
136+
epics: {
137+
test: {
138+
getDataError: false,
139+
getDataErrorCounter: 0,
140+
},
141+
},
142+
});
143+
done();
144+
}, 3000);
145+
});
146+
});

0 commit comments

Comments
 (0)