import { IReduxAction , IReduxAsyncAction } from '../../schemas' ; export function * nerverThrowWrapper ( worker , action ) { try { yield worker ( action ) ; } catch ( e ) { console . error ( e ) ; } } export function * noWrapper ( worker , action ) { yield worker ( action ) ; } export function * handlePromiseWrapper ( worker , action ) { try { const result = yield worker ( action ) ; return action . resolve ( result ) ; } catch ( e ) { return action . reject ( e ) ; } } export function makeSagaWorkersDispatcher ( workersMap ) { return function * ( action ) { const worker = workersMap [ action . type ] ; if ( worker ) { if ( 'reject' in action && 'resolve' in action ) { yield handlePromiseWrapper ( worker , action as IReduxAsyncAction ) ; } else { yield nerverThrowWrapper ( worker , action ) ; } } } ; }