@barchart/portfolio-api-common 1.0.145 → 1.0.149

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,17 +229,47 @@ module.exports = (() => {
229
229
 
230
230
  const initializeGroupObservers = (group, groupTree) => {
231
231
  addGroupBinding(group, group.registerGroupExcludedChangeHandler((excluded, sender) => {
232
- groupTree.climb((parentGroup, parentTree) => {
233
- let excludedItems = [ ];
232
+ groupTree.climb((parentGroup) => {
233
+ if (parentGroup) {
234
+ let excludedItems = [];
235
+
236
+ currentTree.walk((childGroup) => {
237
+ if (childGroup.excluded) {
238
+ excludedItems = excludedItems.concat(childGroup.items);
239
+ }
240
+ }, false, false);
241
+
242
+ parentGroup.setExcludedItems(array.unique(excludedItems));
243
+ }
244
+ }, false);
245
+
246
+ const treeName = treeDefinition.name;
234
247
 
235
- currentTree.walk((childGroup, childTree) => {
236
- if (childGroup.excluded) {
237
- excludedItems = excludedItems.concat(childGroup.items);
248
+ if (treeDefinition.exclusionDependencies.length > 0) {
249
+ const dependantTrees = treeDefinition.exclusionDependencies.reduce((trees, name) => {
250
+ if (this._trees.hasOwnProperty(name)) {
251
+ trees.push(this._trees[name]);
238
252
  }
239
- }, false, false);
240
253
 
241
- parentGroup.setExcludedItems(array.unique(excludedItems));
242
- }, false);
254
+ return trees;
255
+ }, [ ]);
256
+
257
+ if (dependantTrees.length > 0) {
258
+ let excludedItems = [ ];
259
+
260
+ groupTree.walk((childGroup) => {
261
+ if (childGroup.excluded) {
262
+ excludedItems = excludedItems.concat(childGroup.items);
263
+ }
264
+ }, false, false);
265
+
266
+ dependantTrees.forEach((dependantTrees) => {
267
+ dependantTrees.walk((childGroup) => {
268
+ childGroup.setExcludedItems(excludedItems);
269
+ }, false, false);
270
+ });
271
+ }
272
+ }
243
273
  }));
244
274
  };
245
275
 
@@ -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.145",
3
+ "version": "1.0.149",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -945,17 +945,47 @@ module.exports = (() => {
945
945
 
946
946
  const initializeGroupObservers = (group, groupTree) => {
947
947
  addGroupBinding(group, group.registerGroupExcludedChangeHandler((excluded, sender) => {
948
- groupTree.climb((parentGroup, parentTree) => {
949
- let excludedItems = [ ];
948
+ groupTree.climb((parentGroup) => {
949
+ if (parentGroup) {
950
+ let excludedItems = [];
951
+
952
+ currentTree.walk((childGroup) => {
953
+ if (childGroup.excluded) {
954
+ excludedItems = excludedItems.concat(childGroup.items);
955
+ }
956
+ }, false, false);
957
+
958
+ parentGroup.setExcludedItems(array.unique(excludedItems));
959
+ }
960
+ }, false);
961
+
962
+ const treeName = treeDefinition.name;
950
963
 
951
- currentTree.walk((childGroup, childTree) => {
952
- if (childGroup.excluded) {
953
- excludedItems = excludedItems.concat(childGroup.items);
964
+ if (treeDefinition.exclusionDependencies.length > 0) {
965
+ const dependantTrees = treeDefinition.exclusionDependencies.reduce((trees, name) => {
966
+ if (this._trees.hasOwnProperty(name)) {
967
+ trees.push(this._trees[name]);
954
968
  }
955
- }, false, false);
956
969
 
957
- parentGroup.setExcludedItems(array.unique(excludedItems));
958
- }, false);
970
+ return trees;
971
+ }, [ ]);
972
+
973
+ if (dependantTrees.length > 0) {
974
+ let excludedItems = [ ];
975
+
976
+ groupTree.walk((childGroup) => {
977
+ if (childGroup.excluded) {
978
+ excludedItems = excludedItems.concat(childGroup.items);
979
+ }
980
+ }, false, false);
981
+
982
+ dependantTrees.forEach((dependantTrees) => {
983
+ dependantTrees.walk((childGroup) => {
984
+ childGroup.setExcludedItems(excludedItems);
985
+ }, false, false);
986
+ });
987
+ }
988
+ }
959
989
  }));
960
990
  };
961
991
 
@@ -2405,17 +2435,23 @@ module.exports = (() => {
2405
2435
  * @param {Array.<PositionLevelDefinition>} definitions
2406
2436
  */
2407
2437
  class PositionTreeDefinitions {
2408
- constructor(name, definitions) {
2438
+ constructor(name, definitions, exclusionDependencies) {
2409
2439
  assert.argumentIsRequired(name, 'name', String);
2410
2440
  assert.argumentIsArray(definitions, 'definitions', PositionLevelDefinition, 'PositionLevelDefinition');
2411
2441
 
2442
+ if (exclusionDependencies) {
2443
+ assert.argumentIsArray(exclusionDependencies, 'exclusionDependencies', String);
2444
+ }
2445
+
2412
2446
  this._name = name;
2413
2447
  this._definitions = definitions;
2448
+ this._exclusionDependencies = exclusionDependencies || [ ];
2414
2449
  }
2415
2450
 
2416
2451
  /**
2417
2452
  * The name of the tree.
2418
2453
  *
2454
+ * @public
2419
2455
  * @returns {String}
2420
2456
  */
2421
2457
  get name() {
@@ -2435,6 +2471,17 @@ module.exports = (() => {
2435
2471
  return this._definitions;
2436
2472
  }
2437
2473
 
2474
+ /**
2475
+ * Returns the names of other trees which should be impacted when a
2476
+ * group (from the current tree) is excluded.
2477
+ *
2478
+ * @public
2479
+ * @return {Array.<String>}
2480
+ */
2481
+ get exclusionDependencies() {
2482
+ return this._exclusionDependencies;
2483
+ }
2484
+
2438
2485
  toString() {
2439
2486
  return '[PositionTreeDefinitions]';
2440
2487
  }