@legalplace/tagextractor 1.2.0 → 1.3.0

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.
@@ -9,6 +9,8 @@ declare class ConditionsRunner {
9
9
  isOptionRelatedToOption(optionA: number, optionB: number): boolean;
10
10
  isVariableRelatedToOption(variableId: number, optionId: number): boolean;
11
11
  isVariableRelatedToVariable(variableA: number, variableB: number): boolean;
12
+ private executeConditionMemo;
13
+ private buildMemoizeKey;
12
14
  executeCondition(condition: {
13
15
  dataMap: ConditionDataMap;
14
16
  conditions: ConditionV3;
@@ -7,6 +7,8 @@ var lplogic_1 = __importDefault(require("@legalplace/lplogic"));
7
7
  var DataPopulator_1 = __importDefault(require("./DataPopulator"));
8
8
  var ConditionsRunner = (function () {
9
9
  function ConditionsRunner(references, ovc) {
10
+ this.executeConditionMemo = {};
11
+ this.buildMemoizeKey = function (condition, id, index, conditionType) { return JSON.stringify(condition) + "-" + id + "-" + index + "-" + conditionType; };
10
12
  this.references = references;
11
13
  this.ovc = ovc;
12
14
  }
@@ -47,9 +49,9 @@ var ConditionsRunner = (function () {
47
49
  return false;
48
50
  };
49
51
  ConditionsRunner.prototype.executeCondition = function (condition, id, index, conditionType) {
50
- var _this = this;
51
- if (Array.isArray(condition))
52
- return condition.map(function (_condition) { return _this.executeCondition(_condition, id, index, conditionType); });
52
+ var memoizedKey = this.buildMemoizeKey(condition, id, index, conditionType);
53
+ if (this.executeConditionMemo[memoizedKey])
54
+ return this.executeConditionMemo[memoizedKey];
53
55
  var currentData;
54
56
  if (conditionType === 'options' || conditionType === 'optionValidator') {
55
57
  currentData = new DataPopulator_1.default(this, this.references, this.ovc, condition.dataMap, id, index).getData();
@@ -61,7 +63,9 @@ var ConditionsRunner = (function () {
61
63
  else if (conditionType === 'sections' || conditionType === 'documents') {
62
64
  currentData = new DataPopulator_1.default(this, this.references, this.ovc, condition.dataMap, id, index).getData();
63
65
  }
64
- return lplogic_1.default(condition.conditions, currentData);
66
+ var result = lplogic_1.default(condition.conditions, currentData);
67
+ this.executeConditionMemo[memoizedKey] = result;
68
+ return result;
65
69
  };
66
70
  return ConditionsRunner;
67
71
  }());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legalplace/tagextractor",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "TagExtractor",
5
5
  "main": "dist/index.js",
6
6
  "repository": "https://git.legalplace.eu/legalplace/tagextractor",
@@ -70,6 +70,18 @@ class ConditionsRunner {
70
70
  return false
71
71
  }
72
72
 
73
+ private executeConditionMemo: Record<string, any> = {}
74
+
75
+ private buildMemoizeKey = (
76
+ condition: {
77
+ dataMap: ConditionDataMap
78
+ conditions: ConditionV3
79
+ },
80
+ id: number,
81
+ index: number,
82
+ conditionType: 'options' | 'optionValidator' | 'variables' | 'prefillers' | 'variableValidator' | 'sections' | 'documents'
83
+ ) => `${JSON.stringify(condition)}-${id}-${index}-${conditionType}`
84
+
73
85
  executeCondition(
74
86
  condition: {
75
87
  dataMap: ConditionDataMap
@@ -79,7 +91,8 @@ class ConditionsRunner {
79
91
  index: number,
80
92
  conditionType: 'options' | 'optionValidator' | 'variables' | 'prefillers' | 'variableValidator' | 'sections' | 'documents'
81
93
  ): any {
82
- if (Array.isArray(condition)) return condition.map(_condition => this.executeCondition(_condition, id, index, conditionType))
94
+ const memoizedKey = this.buildMemoizeKey(condition, id, index, conditionType)
95
+ if (this.executeConditionMemo[memoizedKey]) return this.executeConditionMemo[memoizedKey]
83
96
 
84
97
  // Populating Data
85
98
  let currentData
@@ -92,7 +105,9 @@ class ConditionsRunner {
92
105
  currentData = new DataPopulator(this, this.references, this.ovc, condition.dataMap, id, index).getData()
93
106
  }
94
107
 
95
- return LpLogic(condition.conditions, currentData)
108
+ const result = LpLogic(condition.conditions, currentData)
109
+ this.executeConditionMemo[memoizedKey] = result
110
+ return result
96
111
  }
97
112
  }
98
113