Saga里面的地图呼叫不起作用

时间:2017-07-19 04:16:32

标签: react-native redux-saga saga

花了几个小时试图找出如何在地图中并行运行传奇。

尝试了我发现的内容:yield result.map(item => call(api.endpoint, item)) 但似乎没有任何事情发生。

这就是我在做的事情:

export function* syncCanvasesByFolder(<someParams>) {
    yield call(api.syncCanvasForFolder, <someParam>);
}

export default function* syncAllFoldersForSurvey(<someParams>) {

    // Get list of folder for a survey
    const folders = yield call(data.getFolderBySurvey, surveyId);

    //For each folder sync canvases

    yield all(folders.map(folder => {
           call(syncCanvasesByFolder, folder.id, lastSyncedAt, access_token)  
    }));

/*Sequential call*/
// for (const i in folders) {
//     if (folders.hasOwnProperty(i)) {
//         yield call(syncCanvasesByFolder, folders[i].id, lastSyncedAt, access_token);
//       //  yield call(canvasSyncSaga.syncAllCanvasesForFolder, folders[i].id, lastSyncedAt);
//     }
// }
}

在for循环中完成顺序调用正在运行。但地图内似乎没有任何事情发生。没有得到任何exception/errors

当我使用map时,

syncCanvasesByFolder永远不会被调用。

2 个答案:

答案 0 :(得分:1)

要隐式返回,请不要在函数内使用大括号{}

使用括号(不工作)

yield all(folders.map(folder => {
    call(syncCanvasesByFolder, folder.id, lastSyncedAt, access_token)  
}));

没有括号(作品)

yield all(folders.map(folder => call(syncCanvasesByFolder, folder.id, lastSyncedAt, access_token)  
));

答案 1 :(得分:0)

使用括号,您必须使用返回

yield all(folders.map(folder => {
    return call(syncCanvasesByFolder, folder.id, lastSyncedAt, access_token)  
}));

没有括号,返回是隐含的

yield all(folders.map(folder => call(syncCanvasesByFolder, folder.id, lastSyncedAt, access_token)  
));