MDL-83673 core_courseformat: optimize pageitem update

The course page employs a scroll spy to highlight the
relevant element in the course index. However, the
frequency of updates is excessively high. This commit add
throttling of the scroll spy and prevents the page item
state from updating if the value hasn’t changed.
This commit is contained in:
ferran
2024-12-20 12:29:58 +01:00
parent a97ddeb2a2
commit f6cfb1ebc3
6 changed files with 10 additions and 7 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -23,7 +23,7 @@
*/
import {BaseComponent} from 'core/reactive';
import {debounce} from 'core/utils';
import {throttle, debounce} from 'core/utils';
import {getCurrentCourseEditor} from 'core_courseformat/courseeditor';
import Config from 'core/config';
import inplaceeditable from 'core/inplace_editable';
@@ -151,7 +151,7 @@ export default class Component extends BaseComponent {
this.addEventListener(
document,
"scroll",
this._scrollHandler
throttle(this._scrollHandler.bind(this), 50)
);
}
@@ -579,9 +579,12 @@ export default class {
return;
}
}
const course = stateManager.get('course');
if (course.pageItem && course.pageItem.type === type && course.pageItem.id === id) {
return;
}
stateManager.setReadOnly(false);
// Remove the current page item.
const course = stateManager.get('course');
course.pageItem = null;
// Save the new page item.
if (newPageItem) {