Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: changedMonitors.forEach (montage.js) #4039

Merged
merged 2 commits into from
May 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions web/skins/classic/views/js/montage.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ function initPage() {

setInterval(() => { //Updating GridStack resizeToContent, Scale & Ratio
if (changedMonitors.length > 0) {
changedMonitors.forEach(function(item, index, object) {
changedMonitors.slice().reverse().forEach(function(item, index, object) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not clear to the casual observer why the slice and reverse are neccessary. perhaps a comment would help.
Alternatively a simple for loop instead of a forEach is actually faster and you can just clear the array at the end. Would be easier to read as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the time of execution of this code, other data may be filled into the "changedMonitors" array. Therefore, it cannot be cleaned after processing all elements. Step by step cleaning is required. This is why "for" is not used.
slice().reverse() - to iterate over a copy of the array from the end, otherwise it will not be possible to correctly remove the processed monitor from the array

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha! Excellent content for a comment.

So the slice makes a copy... which we could use for on. Maybe we should just use a while with popping off elements until the array is empty... so that if another item gets added we will process it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not ready to say anything yet.

const value = getSelected(document.getElementById("ratio"+item));
const img = document.getElementById('liveStream'+item);
const currentMonitor = monitors.find((o) => {
Expand All @@ -818,7 +818,7 @@ function initPage() {

if (img.offsetHeight > 20 && objGridStack) { //Required for initial page loading
objGridStack.resizeToContent(document.getElementById('m'+item));
changedMonitors.splice(index, 1);
changedMonitors.splice(object.length - 1 - index, 1);
}
monitorsSetScale(item);
});
Expand Down
Loading