Skip to content

Commit

Permalink
Update calculated lesson entry attributes only when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
caebr committed May 12, 2021
1 parent 4de01b5 commit 32b5722
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/app/presence-control/models/lesson-entry.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export function fromLesson(lesson: Lesson): LessonEntry {
* Represents a grouping of Lessons by time/teacher.
*/
export class LessonEntry {
readonly id: string;
readonly studyClassNumbers: string;
readonly eventDesignations: string;

lessons = [] as Array<Lesson>;

constructor(
Expand All @@ -41,23 +45,26 @@ export class LessonEntry {
addLesson(lesson: Lesson): void {
if (!this.lessons.some((l) => lessonsEqual(l, lesson))) {
this.lessons.push(lesson);
this.updateId();
this.updateStudyClassNumbers();
this.updateEventDesignations();
}
}

get id(): string {
return [...new Set(this.lessons.map((l) => l.LessonRef.Id).sort())].join(
'-'
);
private updateId(): void {
(this.id as string) = [
...new Set(this.lessons.map((l) => l.LessonRef.Id).sort()),
].join('-');
}

get studyClassNumbers(): string {
return [
private updateStudyClassNumbers(): void {
(this.studyClassNumbers as string) = [
...new Set(this.lessons.map((l) => l.StudyClassNumber).sort()),
].join(', ');
}

get eventDesignations(): string {
return [
private updateEventDesignations(): void {
(this.eventDesignations as string) = [
...new Set(this.lessons.map((l) => l.EventDesignation).sort()),
].join(', ');
}
Expand Down

0 comments on commit 32b5722

Please sign in to comment.