forEach => for

This commit is contained in:
zhw2590582 committed 2022-01-07 22:11:48 +08:00
1 parent 99f5694100
commit 455e2189a7
18 files changed
+159 -103

No files matched your search

+9 -12
View File
@@ -5,15 +5,15 @@ export default class Info extends Component {
constructor(art) {
super(art);
this.name = 'info';
if (this.art.template.$info) {
art.once('ready', () => {
this.init();
}
});
}
init() {
const {
template: { $infoPanel, $infoClose, $video },
events: { proxy },
template: { $infoPanel, $infoClose, $video },
} = this.art;
proxy($infoClose, 'click', () => {
@@ -21,27 +21,24 @@ export default class Info extends Component {
});
let timer = null;
const types = queryAll('[data-video]', $infoPanel);
const types = queryAll('[data-video]', $infoPanel) || [];
this.art.on('destroy', () => {
clearTimeout(timer);
});
function loop() {
types.forEach((item) => {
for (let index = 0; index < types.length; index++) {
const item = types[index];
const value = $video[item.dataset.video];
item.innerText = typeof value === 'number' ? value.toFixed(2) : value;
});
}
timer = setTimeout(() => {
loop();
}, 1000);
}
this.art.on('info', (value) => {
clearTimeout(timer);
if (value) {
loop();
}
});
loop();
}
}