[O] Cache assignment types
This commit is contained in:
+8
-1
@@ -222,10 +222,14 @@ export default class Course
|
|||||||
return this._cacheNumericGrade;
|
return this._cacheNumericGrade;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _cacheAssignmentTypes: AssignmentType[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get assignment types
|
* Get assignment types
|
||||||
*/
|
*/
|
||||||
get assignmentTypes(): AssignmentType[]
|
get assignmentTypes(): AssignmentType[]
|
||||||
|
{
|
||||||
|
if (this._cacheAssignmentTypes == null)
|
||||||
{
|
{
|
||||||
// Get all types
|
// Get all types
|
||||||
let types = this.assignments.map(a => a.type);
|
let types = this.assignments.map(a => a.type);
|
||||||
@@ -237,7 +241,7 @@ export default class Course
|
|||||||
let totalScoreMax = this.assignments.reduce((sum, a) => sum + a.scoreMax, 0);
|
let totalScoreMax = this.assignments.reduce((sum, a) => sum + a.scoreMax, 0);
|
||||||
|
|
||||||
// For every type...
|
// For every type...
|
||||||
return types.map(type =>
|
this._cacheAssignmentTypes = types.map(type =>
|
||||||
{
|
{
|
||||||
// Get assignments of the type
|
// Get assignments of the type
|
||||||
let typeAssignments = this.assignments.filter(a => a.type == type);
|
let typeAssignments = this.assignments.filter(a => a.type == type);
|
||||||
@@ -254,4 +258,7 @@ export default class Course
|
|||||||
return {name: type, id: typeAssignments[0].typeId, weight: weight, scoreMax: scoreMax, score: score}
|
return {name: type, id: typeAssignments[0].typeId, weight: weight, scoreMax: scoreMax, score: score}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this._cacheAssignmentTypes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user