import { getFindBooks , getFindCourses , getFindDocs , getFindRecommend , getFindResources , getFindVoices } from "../services" ; export default { namespace : 'find' , state : { recommend : { } , books : { } , docs : { } , courses : { } , resources : { } , voices : { } } , effects : { * getRecommend ( action , { call , put , select } ) { const { callback } = action ; const recommend = yield select ( ( store ) => store . find . recommend ) ; try { const res = yield call ( getFindRecommend ) ; yield put ( { type : 'save' , payload : { recommend : { init : true , ... res . data } } } ) ; callback && callback ( res . code === 200 ) ; } catch ( e ) { yield put ( { type : 'save' , payload : { recommend : { ... recommend , error : e } } } ) ; } } , * getBooks ( action , { call , put , select } ) { const { callback } = action ; const books = yield select ( ( store ) => store . find . books ) ; try { const res = yield call ( getFindBooks ) ; yield put ( { type : 'save' , payload : { books : { init : true , ... res . data } } } ) ; callback && callback ( res . code === 200 ) ; } catch ( e ) { yield put ( { type : 'save' , payload : { books : { ... books , error : e } } } ) ; } } , * getDocs ( action , { call , put , select } ) { const { callback } = action ; const docs = yield select ( ( store ) => store . find . docs ) ; try { const res = yield call ( getFindDocs ) ; yield put ( { type : 'save' , payload : { docs : { init : true , ... res . data } } } ) ; callback && callback ( res . code === 200 ) ; } catch ( e ) { yield put ( { type : 'save' , payload : { docs : { ... docs , error : e } } } ) ; } } , * getCourses ( action , { call , put , select } ) { const { callback } = action ; const courses = yield select ( ( store ) => store . find . courses ) ; try { const res = yield call ( getFindCourses ) ; yield put ( { type : 'save' , payload : { courses : { init : true , ... res . data } } } ) ; callback && callback ( res . code === 200 ) ; } catch ( e ) { yield put ( { type : 'save' , payload : { courses : { ... courses , error : e } } } ) ; } } , * getResources ( action , { call , put , select } ) { const { callback } = action ; const resources = yield select ( ( store ) => store . find . resources ) ; try { const res = yield call ( getFindResources ) ; yield put ( { type : 'save' , payload : { resources : { init : true , ... res . data } } } ) ; callback && callback ( res . code === 200 ) ; } catch ( e ) { yield put ( { type : 'save' , payload : { resources : { ... resources , error : e } } } ) ; } } , * getVoices ( action , { call , put , select } ) { const { callback } = action ; const voices = yield select ( ( store ) => store . find . voices ) ; try { const res = yield call ( getFindVoices ) ; yield put ( { type : 'save' , payload : { voices : { init : true , ... res . data } } } ) ; callback && callback ( res . code === 200 ) ; } catch ( e ) { yield put ( { type : 'save' , payload : { voices : { ... voices , error : e } } } ) ; } } } , reducers : { save ( state , { payload } ) { return { ... state , ... payload } ; } , } } ;