Skip to content

Commit

Permalink
Reverted changes on get() function
Browse files Browse the repository at this point in the history
My misunderstanding of this function introduced a breaking change, which @oliverfoster caught.

A better solution is to standardise the handling of undefined or assessment 'id' values which are empty strings.  Warning messages are now output when appropriate, but the code allows an empty assessment 'id', e.g. if there is only one assessment on the course.
  • Loading branch information
brian-learningpool committed Jun 27, 2017
1 parent fd822eb commit 4ec4121
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions js/assessment.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ define([
},

_getStateByAssessmentId: function(assessmentId) {
if (!_.isEmpty(assessmentId)) {
return this._assessments._byAssessmentId[assessmentId].getState();
} else {
return this._assessments[0].getState();
if (assessmentId === undefined) {
return null;
}

return this._assessments._byAssessmentId[assessmentId].getState();
},

_getStatesByAssessmentId: function() {
Expand Down Expand Up @@ -231,14 +231,18 @@ define([
}
this._assessments._byPageId[pageId].push(assessmentModel);

if (assessmentId) {
if (assessmentId !== undefined) {
if (assessmentId === '') {
console.warn("An assessment has been registered with an empty value for 'id'");
}

if (!this._assessments._byAssessmentId[assessmentId]) {
this._assessments._byAssessmentId[assessmentId] = assessmentModel;
} else {
console.warn("An assessment with an id of '" + assessmentId + "' already exists!");
}
} else {
console.warn("An assessment has been registered with an empty value for 'id'");
console.warn("An assessment has been registered with an undefined value for 'id'");
}

this._assessments.push(assessmentModel);
Expand All @@ -251,8 +255,8 @@ define([
},

get: function(id) {
if (_.isEmpty(id)) {
return this._assessments[0];
if (id === undefined ) {
return this._assessments.slice(0);
} else {
return this._assessments._byAssessmentId[id];
}
Expand Down

0 comments on commit 4ec4121

Please sign in to comment.