Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Removing existing listeners before language change then re-add #132 #133

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
);
ethan-lp marked this conversation as resolved.
Show resolved Hide resolved
}

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

removeEventListeners() {
// Stop listening to all events
this.stopListening();
}
ethan-lp marked this conversation as resolved.
Show resolved Hide resolved

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