mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-16 01:26:16 -08:00
feat: Refactor worker.js to use dynamic function dispatch
This commit is contained in:
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,
|
||||
});
|
||||
};
|
||||
Reference in new issue
Block a user