close

1.

import { take, put,takeLatest, call, fork, select, takeEvery, all } from 'redux-saga/effects'

import  {getJobList} from './jobSaga'
import  {watchLogin} from './userSaga'


export default function* rootSaga(){
    yield  fork( getJobList)
  yield  fork( watchLogin )


}
2.

import { take, put,takeLatest, call, fork, select, takeEvery, all } from 'redux-saga/effects'
import axios from 'axios'
import {REQUST_FETCH_JOBLIST} from '../constant/jobActionType'
import {fetchJobList} from '../api/api'
import {fetchJobListSucess} from '../actions/jobAction'
import {fetchJobListFailed} from '../actions/jobAction'

 export function *getJobList(){
while(true){
  const action=yield take('REQUST_FETCH_JOBLIST')
  try{
    const {data}= yield call(fetchJobList,action.data)
    yield put(fetchJobListSucess(data))
  }catch(e){
    yield put(fetchJobListFailed(e.response.data))

  }
}


}
 

3.

import { take, put,takeLatest, call, fork, select, takeEvery, all } from 'redux-saga/effects'
import {REQUEST_LOGIN,
  FETCH_LOGIN_FAILED,
  FETCH_LOGIN_SUCCESS
} from '../constant/userActionType'
import {fetchLogin} from '../api/api'
import {requestLogin,fetchLoginFailed,fetchLoginSuccess} from '../actions/userAction'
export  function *watchLogin(){
  while(true){
    const action=yield take('REQUEST_LOGIN')
    try{
      alert('user login')
      const data= yield call(fetchLogin,action.data)
      yield put(fetchLoginSuccess(data))

    }catch(e){
      alert('falt')

      yield put(fetchLoginFailed(e.response.data))

    }
  }
}

5. fork然後user和product的take監聽action 用while
 

 

arrow
arrow
    全站熱搜

    學習程式 發表在 痞客邦 留言(0) 人氣()