From 536589c591ad26095c2a0decf3a5c5c0c615f592 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 25 May 2020 10:21:23 +0200 Subject: [PATCH] MOBILE-3401 course: Prevent JS errors when clearing option handlers --- src/core/course/providers/options-delegate.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/core/course/providers/options-delegate.ts b/src/core/course/providers/options-delegate.ts index 9d2745056..815be116e 100644 --- a/src/core/course/providers/options-delegate.ts +++ b/src/core/course/providers/options-delegate.ts @@ -243,11 +243,17 @@ export class CoreCourseOptionsDelegate extends CoreDelegate { */ protected clearCoursesHandlers(courseId?: number): void { 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; delete this.coursesHandlers[courseId]; } else { - this.loaded = {}; - this.coursesHandlers = {}; + for (const courseId in this.coursesHandlers) { + this.clearCoursesHandlers(Number(courseId)); + } } } @@ -484,7 +490,7 @@ export class CoreCourseOptionsDelegate extends CoreDelegate { const promises = [], courseData = this.coursesHandlers[courseId]; - if (!courseData) { + if (!courseData || !courseData.enabledHandlers) { return Promise.resolve(); }