https://snack.expo.io/@haosmark/kw-companion2
在api.js文件中,当我在第17行将debugMode设置为false时,该应用程序不会出现打works的情况。它获取球员,房间和比赛的列表,但是,如果我将其设置为debugMode false,则该应用程序将在线显示0个球员,并在“托管房间”和“活跃游戏”选项卡上复制活跃比赛。如何正确模拟带有伪数据的网络请求?上面是完整的代码,下面是有问题的函数:
export const fetchDataAsync = async () => {
playerList = {};
activeGames = {};
stagingRooms = {};
//console.log('fetching data')
if (debugMode) {
result = await mockDataSmall.cnc3kw;
} else {
const response = await fetch(url);
result = (await response.json()).cnc3kw;
}
//console.log('here0')
Object.keys(result.users).map(parsePlayers);
result.games.playing.map(parseRooms(ACTIVE_MATCH));
result.games.staging.map(parseRooms(STAGING_ROOM));
//console.log('here1')
if (debugMode) {
new Promise((resolve, reject) => {
setTimeout(() => {
resolve('success');
}, 1000);
});
}
//console.log('here2')
return { playerList, activeGames, stagingRooms };
};
fakeData与实时数据的格式相同,但样本较小