@vived/app 3.9.1 → 3.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ export declare class SerializeQuestionChallenge implements SerializedSystem {
6
6
  getSystemState(): object;
7
7
  applySystemState(state: object, version: number): void;
8
8
  applyDefaultState(): void;
9
- private applyDataV1;
9
+ private mapV1ToV2;
10
10
  private applyDataV2;
11
11
  constructor(questionChallenge: QuestionChallenge, stateMachine: StateMachine);
12
12
  }
@@ -28,8 +28,8 @@ class SerializeQuestionChallenge {
28
28
  }
29
29
  applySystemState(state, version) {
30
30
  if (state && version === 1) {
31
- const castState = state;
32
- this.applyDataV1(castState);
31
+ const v2Data = this.mapV1ToV2(state);
32
+ this.applyDataV2(v2Data);
33
33
  }
34
34
  else if (state && version === 2) {
35
35
  const castState = state;
@@ -44,26 +44,33 @@ class SerializeQuestionChallenge {
44
44
  applyDefaultState() {
45
45
  this.questionChallenge.setDefaultState();
46
46
  }
47
- applyDataV1(data) {
48
- this.questionChallenge.removeAllAnswers();
49
- this.questionChallenge.text = "";
50
- data.answers.forEach((answerData) => {
51
- const answer = Entities_1.makeQuestionChallengeAnswer(answerData.id);
52
- answer.text = answerData.text;
53
- answer.isCorrect = answerData.isCorrect;
54
- answer.feedbackText = answerData.feedback;
55
- this.questionChallenge.addAnswer(answer);
56
- });
47
+ mapV1ToV2(data) {
48
+ return {
49
+ questionText: "",
50
+ answers: data.answers,
51
+ };
57
52
  }
58
53
  applyDataV2(data) {
59
- this.questionChallenge.removeAllAnswers();
60
54
  this.questionChallenge.text = data.questionText;
55
+ const stateAnswers = [];
61
56
  data.answers.forEach((answerData) => {
62
- const answer = Entities_1.makeQuestionChallengeAnswer(answerData.id);
57
+ let answer = this.questionChallenge.getAnswer(answerData.id);
58
+ if (!answer) {
59
+ answer = Entities_1.makeQuestionChallengeAnswer(answerData.id);
60
+ }
63
61
  answer.text = answerData.text;
64
62
  answer.isCorrect = answerData.isCorrect;
65
63
  answer.feedbackText = answerData.feedback;
66
64
  this.questionChallenge.addAnswer(answer);
65
+ stateAnswers.push(answer.id);
66
+ });
67
+ const allAnswers = this.questionChallenge.getAllAnswers().map((ans) => {
68
+ return ans.id;
69
+ });
70
+ allAnswers.forEach((ansID) => {
71
+ if (!stateAnswers.includes(ansID)) {
72
+ this.questionChallenge.removeAnswer(ansID);
73
+ }
67
74
  });
68
75
  }
69
76
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vived/app",
3
- "version": "3.9.1",
3
+ "version": "3.9.2",
4
4
  "description": "Public package for the VIVED Learning App system",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",