@barchart/portfolio-api-common 1.0.146 → 1.0.150

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.
@@ -229,11 +229,11 @@ module.exports = (() => {
229
229
 
230
230
  const initializeGroupObservers = (group, groupTree) => {
231
231
  addGroupBinding(group, group.registerGroupExcludedChangeHandler((excluded, sender) => {
232
- groupTree.climb((parentGroup, parentTree) => {
233
- if (parentGroup !== null) {
232
+ groupTree.climb((parentGroup) => {
233
+ if (parentGroup) {
234
234
  let excludedItems = [];
235
235
 
236
- currentTree.walk((childGroup, childTree) => {
236
+ currentTree.walk((childGroup) => {
237
237
  if (childGroup.excluded) {
238
238
  excludedItems = excludedItems.concat(childGroup.items);
239
239
  }
@@ -242,6 +242,32 @@ module.exports = (() => {
242
242
  parentGroup.setExcludedItems(array.unique(excludedItems));
243
243
  }
244
244
  }, false);
245
+
246
+ if (treeDefinition.exclusionDependencies.length > 0) {
247
+ const dependantTrees = treeDefinition.exclusionDependencies.reduce((trees, name) => {
248
+ if (this._trees.hasOwnProperty(name)) {
249
+ trees.push(this._trees[name]);
250
+ }
251
+
252
+ return trees;
253
+ }, [ ]);
254
+
255
+ if (dependantTrees.length > 0) {
256
+ let excludedItems = [ ];
257
+
258
+ tree.walk((childGroup) => {
259
+ if (childGroup.excluded) {
260
+ excludedItems = excludedItems.concat(childGroup.items);
261
+ }
262
+ }, false, false);
263
+
264
+ dependantTrees.forEach((dependantTrees) => {
265
+ dependantTrees.walk((childGroup) => {
266
+ childGroup.setExcludedItems(excludedItems);
267
+ }, false, false);
268
+ });
269
+ }
270
+ }
245
271
  }));
246
272
  };
247
273
 
@@ -13,17 +13,23 @@ module.exports = (() => {
13
13
  * @param {Array.<PositionLevelDefinition>} definitions
14
14
  */
15
15
  class PositionTreeDefinitions {
16
- constructor(name, definitions) {
16
+ constructor(name, definitions, exclusionDependencies) {
17
17
  assert.argumentIsRequired(name, 'name', String);
18
18
  assert.argumentIsArray(definitions, 'definitions', PositionLevelDefinition, 'PositionLevelDefinition');
19
19
 
20
+ if (exclusionDependencies) {
21
+ assert.argumentIsArray(exclusionDependencies, 'exclusionDependencies', String);
22
+ }
23
+
20
24
  this._name = name;
21
25
  this._definitions = definitions;
26
+ this._exclusionDependencies = exclusionDependencies || [ ];
22
27
  }
23
28
 
24
29
  /**
25
30
  * The name of the tree.
26
31
  *
32
+ * @public
27
33
  * @returns {String}
28
34
  */
29
35
  get name() {
@@ -43,6 +49,17 @@ module.exports = (() => {
43
49
  return this._definitions;
44
50
  }
45
51
 
52
+ /**
53
+ * Returns the names of other trees which should be impacted when a
54
+ * group (from the current tree) is excluded.
55
+ *
56
+ * @public
57
+ * @return {Array.<String>}
58
+ */
59
+ get exclusionDependencies() {
60
+ return this._exclusionDependencies;
61
+ }
62
+
46
63
  toString() {
47
64
  return '[PositionTreeDefinitions]';
48
65
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.146",
3
+ "version": "1.0.150",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -945,11 +945,11 @@ module.exports = (() => {
945
945
 
946
946
  const initializeGroupObservers = (group, groupTree) => {
947
947
  addGroupBinding(group, group.registerGroupExcludedChangeHandler((excluded, sender) => {
948
- groupTree.climb((parentGroup, parentTree) => {
949
- if (parentGroup !== null) {
948
+ groupTree.climb((parentGroup) => {
949
+ if (parentGroup) {
950
950
  let excludedItems = [];
951
951
 
952
- currentTree.walk((childGroup, childTree) => {
952
+ currentTree.walk((childGroup) => {
953
953
  if (childGroup.excluded) {
954
954
  excludedItems = excludedItems.concat(childGroup.items);
955
955
  }
@@ -958,6 +958,32 @@ module.exports = (() => {
958
958
  parentGroup.setExcludedItems(array.unique(excludedItems));
959
959
  }
960
960
  }, false);
961
+
962
+ if (treeDefinition.exclusionDependencies.length > 0) {
963
+ const dependantTrees = treeDefinition.exclusionDependencies.reduce((trees, name) => {
964
+ if (this._trees.hasOwnProperty(name)) {
965
+ trees.push(this._trees[name]);
966
+ }
967
+
968
+ return trees;
969
+ }, [ ]);
970
+
971
+ if (dependantTrees.length > 0) {
972
+ let excludedItems = [ ];
973
+
974
+ tree.walk((childGroup) => {
975
+ if (childGroup.excluded) {
976
+ excludedItems = excludedItems.concat(childGroup.items);
977
+ }
978
+ }, false, false);
979
+
980
+ dependantTrees.forEach((dependantTrees) => {
981
+ dependantTrees.walk((childGroup) => {
982
+ childGroup.setExcludedItems(excludedItems);
983
+ }, false, false);
984
+ });
985
+ }
986
+ }
961
987
  }));
962
988
  };
963
989
 
@@ -2407,17 +2433,23 @@ module.exports = (() => {
2407
2433
  * @param {Array.<PositionLevelDefinition>} definitions
2408
2434
  */
2409
2435
  class PositionTreeDefinitions {
2410
- constructor(name, definitions) {
2436
+ constructor(name, definitions, exclusionDependencies) {
2411
2437
  assert.argumentIsRequired(name, 'name', String);
2412
2438
  assert.argumentIsArray(definitions, 'definitions', PositionLevelDefinition, 'PositionLevelDefinition');
2413
2439
 
2440
+ if (exclusionDependencies) {
2441
+ assert.argumentIsArray(exclusionDependencies, 'exclusionDependencies', String);
2442
+ }
2443
+
2414
2444
  this._name = name;
2415
2445
  this._definitions = definitions;
2446
+ this._exclusionDependencies = exclusionDependencies || [ ];
2416
2447
  }
2417
2448
 
2418
2449
  /**
2419
2450
  * The name of the tree.
2420
2451
  *
2452
+ * @public
2421
2453
  * @returns {String}
2422
2454
  */
2423
2455
  get name() {
@@ -2437,6 +2469,17 @@ module.exports = (() => {
2437
2469
  return this._definitions;
2438
2470
  }
2439
2471
 
2472
+ /**
2473
+ * Returns the names of other trees which should be impacted when a
2474
+ * group (from the current tree) is excluded.
2475
+ *
2476
+ * @public
2477
+ * @return {Array.<String>}
2478
+ */
2479
+ get exclusionDependencies() {
2480
+ return this._exclusionDependencies;
2481
+ }
2482
+
2440
2483
  toString() {
2441
2484
  return '[PositionTreeDefinitions]';
2442
2485
  }