Skip to content

Commit 42cdcb6

Browse files
committed
recover with identity if reducer throw error, so other reducer can still work without block by it
1 parent df47f69 commit 42cdcb6

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

ROADMAP.org

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
* RoadMap [0%]
1+
* RoadMap [50%]
22

3-
- [ ] modular, extra engine.
4-
- [ ] time travel
5-
- [ ] inspect
6-
- [ ] history.back()
3+
- [X] modular, extra engine.
4+
- [X] time travel
5+
- [X] inspect
6+
- [X] history.back()
77
- [ ] unsubscribe when component unmount
8-
- [ ] todo example
8+
- [X] todo example
99
- [ ] router example
10-
- [ ]
10+
- [ ] typescript typedef
11+
- [ ] flow type

lib/__tests__/react-most-test.jsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,37 @@ describe('react-most', () => {
250250
.then(state=>expect(state.count).toEqual(6))
251251
})
252252
})
253+
254+
describe('convension default to `action` field in sinks', ()=>{
255+
const Counter = connect(intent$=>{
256+
return {
257+
sink$: intent$.map(intent=>{
258+
switch(intent.type) {
259+
case 'exception':
260+
throw new Error('exception in reducer')
261+
default:
262+
return state=>state
263+
}
264+
}),
265+
actions: {
266+
throwExeption: ()=>({type: 'exception'})
267+
},
268+
}
269+
})(CounterView)
270+
271+
it('should recover to identity stream and log exception', ()=>{
272+
spyOn(console, 'error')
273+
let counterWrapper = TestUtils.renderIntoDocument(
274+
<Most >
275+
<Counter history={true} />
276+
</Most>
277+
)
278+
let counter = TestUtils.findRenderedComponentWithType(counterWrapper, Counter)
279+
return do$([
280+
counter.actions.throwExeption,
281+
]).then(()=>{
282+
expect(console.error).toHaveBeenCalled()
283+
})
284+
})
285+
})
253286
})

lib/engine/most.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {from,mergeArray} from 'most'
1+
import {from, of, mergeArray} from 'most'
22
import {async as subject} from 'most-subject'
33
export default function Engine() {
44
const intentStream = subject(),
@@ -9,7 +9,12 @@ export default function Engine() {
99
travelStream.send = travelStream.next.bind(travelStream);
1010

1111
function flatObserve(actionsSinks, f){
12-
return mergeArray(actionsSinks).observe(f);
12+
return mergeArray(actionsSinks)
13+
.recoverWith(e => {
14+
console.error('There is Error in your reducer:',e, e.stack)
15+
return of(x=>x)
16+
})
17+
.observe(f);
1318
}
1419
historyStream.travel = travelStream;
1520
return {intentStream, flatObserve, historyStream}

0 commit comments

Comments
 (0)