feat: Refactor worker.js to use dynamic function dispatch

This commit is contained in:
Harvey Zack committed 2024-06-04 19:12:11 +08:00
1 parent d57a13a2bd
commit 69d99cc478
4 files changed
+15 -7

No files matched your search

@@ -514,7 +514,8 @@ export default class Danmuku {
const distance = clientWidth + danmu.$ref.clientWidth;
// 计算弹幕的top值
const { top } = await this.postMessage({
const { result: top } = await this.postMessage({
type: 'getDanmuTop',
target: {
mode: danmu.mode,
height: danmu.$ref.clientHeight,
@@ -129,10 +129,14 @@ function getDanmuTop({ target, visibles, clientWidth, clientHeight, marginBottom
onmessage = (event) => {
const { data } = event;
if (!data.id) return;
const top = getDanmuTop(data);
if (!data.id || !data.type) return;
const fns = { getDanmuTop };
const fn = fns[data.type];
const result = fn(data);
self.postMessage({
top,
result,
id: data.id,
});
};