Skip to content

Commit

Permalink
Fix: Removing existing listeners before language change then re-add #132
Browse files Browse the repository at this point in the history
 (#133)
  • Loading branch information
ethan-lp authored Sep 27, 2024
1 parent 4365aba commit ae8da86
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions js/XAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,22 @@ class XAPI extends Backbone.Model {
}

async onLanguageChanged(newLanguage) {
// Update the language.
// Remove existing event listeners
this.removeEventListeners();

// Update the language
this.set({ displayLang: newLanguage });

// Since a language change counts as a new attempt, reset the state.
// Since a language change counts as a new attempt, reset the state
await this.deleteState();
// Send a statement to track the (new) course.
await this.sendStatement(this.getCourseStatement(window.ADL.verbs.launched));

// Re-add event listeners for the new language/session
this.setupListeners();

// Send a statement to track the (new) course
await this.sendStatement(
this.getCourseStatement(window.ADL.verbs.launched)
);
}

/**
Expand Down Expand Up @@ -452,6 +461,11 @@ class XAPI extends Backbone.Model {
});
}

removeEventListeners() {
// Stop listening to all events
this.stopListening();
}

/**
* Gets an xAPI Activity (with an 'id of the activityId) representing the course.
* @returns {window.ADL.XAPIStatement.Activity} Activity representing the course.
Expand Down

0 comments on commit ae8da86

Please sign in to comment.