What if redux-saga executes the same method twice and each time the last method succeeds?

clipboard.png

componentDidMount() {
    // getTaskState
    // 
    this.props.dispatch(getTaskState("status"))
    this.props.dispatch(getTaskState("type"))
}
    
const homeReducer = (state=initialState, action) => {
    if(action.type === GET_TASKSTYPE_SUCCESS){
        return Object.assign({}, state, {
            taskTypeData: action.taskTypeData
        })
    }
    if(action.type === GET_TASKSTATE_SUCCESS){
        return Object.assign({}, state, {
            taskStateData: action.taskStateData
        })
    }
    
   ...

   return state;
}
export default homeReducer;
import { put, call, takeLatest } from "redux-saga/effects";
import { getTaskStateFaild, GET_TASKSTATE, getTaskStateSuccess,getTaskTypeSuccess } from "../../actions/commonAction";
import { fetch } from "@/util/request";
import { message } from "antd";

const fetchTaskCount=(typeName)=>{
    return fetch("fetchTaskCountAll",{ type: typeName })
}

export function* fetchTaskState(action){
    console.log("action is", action);
    
    try{
        yield takeLatest(GET_TASKSTATE, fetchTaskState);
        const response = yield call(fetchTaskCount, action.typeName);
        if(!response.data.success){
            message.error(response.data.message);
            return;
        }
        if(action.typeName == "status"){
            yield put(getTaskStateSuccess(response.data.data))
        }else if(action.typeName == "type"){
            yield put(getTaskTypeSuccess(response.data.data))
        }

    }catch(error){
        yield put(getTaskStateFaild(error))
    }
}
Jul.15,2022

clipboard.png

< H1 > has been solved. Change the taskLatest in redux-saga to takeEvery and it is successful. < / H1 >
import { put, call, takeLatest, takeEvery } from 'redux-saga/effects';
import { getTaskStateFaild, GET_TASKSTATE, getTaskStateSuccess,getTaskTypeSuccess } from '../../actions/commonAction';
import { fetch } from '@/util/request';
import { message } from 'antd';

const fetchTaskCount=(typeName)=>{
    return fetch("fetchTaskCountAll",{ type: typeName })
}

export function* fetchTaskState(action){
    
    try{
        // takeEvery 
        yield takeEvery(GET_TASKSTATE, fetchTaskState);
        console.log('call yield before: ', action.typeName);        
        const response = yield call(fetchTaskCount, action.typeName);
        console.log('call yield after: ', action.typeName);
        if(!response.data.success){
            message.error(response.data.message);
            return;
        }
        if(action.typeName == "status"){
            alert('state1')
            yield put(getTaskStateSuccess(response.data.data))
        }else if(action.typeName == "type"){
            alert('type1')
            yield put(getTaskTypeSuccess(response.data.data))
        }
    }catch(error){
        yield put(getTaskStateFaild(error))
    }
}

reference

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b22648-40653.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b22648-40653.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?