if-else to swithc-case

This commit is contained in:
mrfry 2023-09-16 09:22:37 +02:00
parent 834cacc2c7
commit ee30410209

View file

@ -61,33 +61,34 @@ async function handleWorkerData() {
}) })
} }
async function handleMessage( function handleMessage(
qdbs: QuestionDb[], qdbs: QuestionDb[],
msg: TaskObject, msg: TaskObject,
workerIndex: number, workerIndex: number,
setQdbs: (newVal: QuestionDb[]) => void setQdbs: (newVal: QuestionDb[]) => void
) { ) {
if (msg.type === 'search') { switch (msg.type) {
await handleSearch(qdbs, msg, workerIndex) case 'search':
} else if (msg.type === 'merge') { return handleSearch(qdbs, msg, workerIndex)
await handleMerge(qdbs, msg, workerIndex) case 'merge':
} else if (msg.type === 'dbEdit') { return handleMerge(qdbs, msg, workerIndex)
await handleDbEdit(qdbs, msg, workerIndex, setQdbs) case 'dbEdit':
} else if (msg.type === 'newQuestions') { return handleDbEdit(qdbs, msg, workerIndex, setQdbs)
await handleNewQuestions(qdbs, msg, workerIndex, setQdbs) case 'newQuestions':
} else if (msg.type === 'newdb') { return handleNewQuestions(qdbs, msg, workerIndex, setQdbs)
await handleNewDb(qdbs, msg, workerIndex, setQdbs) case 'newdb':
} else if (msg.type === 'dbClean') { return handleNewDb(qdbs, msg, workerIndex, setQdbs)
await handleDbClean(qdbs, msg, workerIndex) case 'dbClean':
} else if (msg.type === 'rmQuestions') { return handleDbClean(qdbs, msg, workerIndex)
await handleRmQuestions(qdbs, msg, workerIndex, setQdbs) case 'rmQuestions':
} else if (msg.type === 'sendQuestionsToPeers') { return handleRmQuestions(qdbs, msg, workerIndex, setQdbs)
await handleQuestionsToPeers(qdbs, msg, workerIndex) case 'sendQuestionsToPeers':
} else if (msg.type === 'sendUsersToPeers') { return handleQuestionsToPeers(qdbs, msg, workerIndex)
await handleUsersToPeers(qdbs, msg, workerIndex) case 'sendUsersToPeers':
} else if (msg.type === 'sendUserFilesToPeers') { return handleUsersToPeers(qdbs, msg, workerIndex)
await handleUserFilesToPeers(qdbs, msg, workerIndex) case 'sendUserFilesToPeers':
} else { return handleUserFilesToPeers(qdbs, msg, workerIndex)
default:
logger.Log(`Invalid msg type!`, logger.GetColor('redbg')) logger.Log(`Invalid msg type!`, logger.GetColor('redbg'))
console.error(msg) console.error(msg)
@ -97,5 +98,7 @@ async function handleMessage(
})!`, })!`,
workerIndex: workerIndex, workerIndex: workerIndex,
}) })
return null
break
} }
} }