Skip to content

Commit

Permalink
fixup! MDL-79194 core_courseformat: optimize section reload
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranrecio committed Oct 18, 2023
1 parent 7a73895 commit 85d68d0
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion course/format/amd/build/local/content.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion course/format/amd/build/local/content.min.js.map

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions course/format/amd/src/local/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,13 +527,13 @@ export default class Component extends BaseComponent {
if (debouncedReload) {
return debouncedReload;
}
const pendingReload = new Pending(pendingKey);
const reload = () => {
const pendingReload = new Pending(pendingKey);
this.debouncedReloads.delete(pendingKey);
const cmitem = this.getElement(this.selectors.CM, cmId);
if (!cmitem) {
pendingReload.resolve();
return;
return pendingReload;
}
const promise = Fragment.loadFragment(
'core_courseformat',
Expand All @@ -558,12 +558,13 @@ export default class Component extends BaseComponent {
}).catch(() => {
pendingReload.resolve();
});
return pendingReload;
};
debouncedReload = debounce(
reload,
200,
{
cancel: true, pending: pendingReload
cancel: true, pending: true
}
);
this.debouncedReloads.set(pendingKey, debouncedReload);
Expand Down
2 changes: 1 addition & 1 deletion lib/amd/build/utils.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/amd/build/utils.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions lib/amd/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ export const debounce = (

const returnedFunction = (...args) => {
if (pending && !debounceMap.has(returnedFunction)) {
if (typeof pending !== 'object') {
pending = new Pending('core/utils:debounce');
}
debounceMap.set(returnedFunction, pending);
debounceMap.set(returnedFunction, new Pending('core/utils:debounce'));
}
clearTimeout(timeout);
timeout = setTimeout(async () => {
Expand Down

0 comments on commit 85d68d0

Please sign in to comment.