MOBILE-3401 course: Prevent JS errors when clearing option handlers

main
Dani Palou 2020-05-25 10:21:23 +02:00
parent fd464d45ce
commit 536589c591
1 changed files with 9 additions and 3 deletions

View File

@ -243,11 +243,17 @@ export class CoreCourseOptionsDelegate extends CoreDelegate {
*/ */
protected clearCoursesHandlers(courseId?: number): void { protected clearCoursesHandlers(courseId?: number): void {
if (courseId) { if (courseId) {
if (!this.loaded[courseId]) {
// Don't clear if not loaded, it's probably an ongoing load and it could cause JS errors.
return;
}
this.loaded[courseId] = false; this.loaded[courseId] = false;
delete this.coursesHandlers[courseId]; delete this.coursesHandlers[courseId];
} else { } else {
this.loaded = {}; for (const courseId in this.coursesHandlers) {
this.coursesHandlers = {}; this.clearCoursesHandlers(Number(courseId));
}
} }
} }
@ -484,7 +490,7 @@ export class CoreCourseOptionsDelegate extends CoreDelegate {
const promises = [], const promises = [],
courseData = this.coursesHandlers[courseId]; courseData = this.coursesHandlers[courseId];
if (!courseData) { if (!courseData || !courseData.enabledHandlers) {
return Promise.resolve(); return Promise.resolve();
} }