@barchart/portfolio-api-common 1.0.176 → 1.0.180

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.
@@ -125,7 +125,7 @@ module.exports = (() => {
125
125
  this._trees = this._definitions.reduce((map, treeDefinition) => {
126
126
  const tree = new Tree();
127
127
 
128
- createGroups.call(this, tree, tree, this._items, treeDefinition, treeDefinition.definitions);
128
+ createGroups.call(this, tree, this._items, treeDefinition, treeDefinition.definitions);
129
129
 
130
130
  map[treeDefinition.name] = tree;
131
131
 
@@ -188,7 +188,7 @@ module.exports = (() => {
188
188
  const overrideRequiredGroups = [ portfolioRequiredGroup ];
189
189
 
190
190
  parentTrees.forEach((t) => {
191
- createGroups.call(this, tree, t, [ ], treeDefinition, levelDefinitions.slice(portfolioLevelDefinitionIndex), overrideRequiredGroups);
191
+ createGroups.call(this, t, [ ], treeDefinition, levelDefinitions.slice(portfolioLevelDefinitionIndex), overrideRequiredGroups);
192
192
  });
193
193
  }
194
194
  });
@@ -242,6 +242,41 @@ module.exports = (() => {
242
242
 
243
243
  this.startTransaction(() => {
244
244
  this.removePosition(position);
245
+
246
+ summaries.forEach((summary) => {
247
+ addSummaryCurrent(this._summariesCurrent, summary, this._currentSummaryFrame, this._currentSummaryRange);
248
+ addSummaryPrevious(this._summariesPrevious, summary, this._previousSummaryFrame, this._previousSummaryRanges);
249
+ });
250
+
251
+ const item = createPositionItem(position);
252
+
253
+ addBarchartSymbol(this._symbols, item);
254
+ addDisplaySymbol(this._symbolsDisplay, item);
255
+
256
+ this._items.push(item);
257
+
258
+ const createGroupOrInjectItem = (parentTree, treeDefinition, levelDefinitions) => {
259
+ const levelDefinition = levelDefinitions[0];
260
+ const levelKey = levelDefinition.keySelector(item);
261
+
262
+ let groupTree;
263
+
264
+ if (parentTree.getChildren().length > 0) {
265
+ groupTree = parentTree.getChildren().findChild(childGroup => childGroup.key === levelKey) || null;
266
+ } else {
267
+ groupTree = null;
268
+ }
269
+
270
+ if (groupTree !== null) {
271
+ groupTree.addItem(item);
272
+
273
+ createGroupOrInjectItem(groupTree, treeDefinition, array.dropLeft(levelDefinitions));
274
+ } else {
275
+ createGroups.call(this, parentTree, [ item ], treeDefinition, levelDefinitions, [ ]);
276
+ }
277
+ };
278
+
279
+ this._definitions.forEach(definition => createGroupOrInjectItem(this._trees[definition.name], definition, definition.definitions));
245
280
  });
246
281
  }
247
282
 
@@ -405,7 +440,7 @@ module.exports = (() => {
405
440
  *
406
441
  * @public
407
442
  * @param {String} name
408
- * @param {Array.<String> keys
443
+ * @param {Array.<String>} keys
409
444
  * @returns {PositionGroup}
410
445
  */
411
446
  getGroup(name, keys) {
@@ -421,7 +456,7 @@ module.exports = (() => {
421
456
  *
422
457
  * @public
423
458
  * @param {String} name
424
- * @param {Array.<String> keys
459
+ * @param {Array.<String>} keys
425
460
  * @returns {Array.<PositionGroup>}
426
461
  */
427
462
  getGroups(name, keys) {
@@ -530,12 +565,62 @@ module.exports = (() => {
530
565
  this._groupBindings[id].push(dispoable);
531
566
  }
532
567
 
533
- function createGroups(parentTree, currentTree, items, treeDefinition, levelDefinitions, overrideRequiredGroups) {
568
+ function initializeGroupObservers(groupTree, treeDefinition) {
569
+ const group = groupTree.getValue();
570
+
571
+ addGroupBinding.call(this, group, group.registerGroupExcludedChangeHandler(() => {
572
+ groupTree.climb((parentGroup, parentTree) => {
573
+ if (parentGroup) {
574
+ let excludedItems = [];
575
+
576
+ parentTree.walk((childGroup) => {
577
+ if (childGroup.excluded) {
578
+ excludedItems = excludedItems.concat(childGroup.items);
579
+ }
580
+ }, false, false);
581
+
582
+ parentGroup.setExcludedItems(array.unique(excludedItems));
583
+ }
584
+ }, false);
585
+
586
+ if (treeDefinition.exclusionDependencies.length > 0) {
587
+ const dependantTrees = treeDefinition.exclusionDependencies.reduce((trees, name) => {
588
+ if (this._trees.hasOwnProperty(name)) {
589
+ trees.push(this._trees[name]);
590
+ }
591
+
592
+ return trees;
593
+ }, [ ]);
594
+
595
+ if (dependantTrees.length > 0) {
596
+ let excludedItems = [ ];
597
+
598
+ groupTree.getRoot().walk((childGroup) => {
599
+ if (childGroup.excluded) {
600
+ excludedItems = excludedItems.concat(childGroup.items);
601
+ }
602
+ }, false, false);
603
+
604
+ dependantTrees.forEach((dependantTrees) => {
605
+ dependantTrees.walk((childGroup) => {
606
+ childGroup.setExcludedItems(excludedItems);
607
+ }, false, false);
608
+ });
609
+ }
610
+ }
611
+ }));
612
+
613
+ addGroupBinding.call(this, group, group.registerMarketPercentChangeHandler(() => {
614
+ groupTree.getParent().walk((childGroup) => childGroup.refreshMarketPercent());
615
+ }));
616
+ }
617
+
618
+ function createGroups(parentTree, items, treeDefinition, levelDefinitions, overrideRequiredGroups) {
534
619
  if (levelDefinitions.length === 0) {
535
620
  return;
536
621
  }
537
622
 
538
- const parent = currentTree.getValue() || null;
623
+ const parent = parentTree.getValue() || null;
539
624
 
540
625
  const levelDefinition = levelDefinitions[0];
541
626
 
@@ -592,60 +677,12 @@ module.exports = (() => {
592
677
 
593
678
  compositeGroups.sort(builder.toComparator());
594
679
 
595
- const initializeGroupObservers = (group, groupTree) => {
596
- addGroupBinding.call(this, group, group.registerGroupExcludedChangeHandler((excluded, sender) => {
597
- groupTree.climb((parentGroup) => {
598
- if (parentGroup) {
599
- let excludedItems = [];
600
-
601
- currentTree.walk((childGroup) => {
602
- if (childGroup.excluded) {
603
- excludedItems = excludedItems.concat(childGroup.items);
604
- }
605
- }, false, false);
606
-
607
- parentGroup.setExcludedItems(array.unique(excludedItems));
608
- }
609
- }, false);
610
-
611
- if (treeDefinition.exclusionDependencies.length > 0) {
612
- const dependantTrees = treeDefinition.exclusionDependencies.reduce((trees, name) => {
613
- if (this._trees.hasOwnProperty(name)) {
614
- trees.push(this._trees[name]);
615
- }
616
-
617
- return trees;
618
- }, [ ]);
619
-
620
- if (dependantTrees.length > 0) {
621
- let excludedItems = [ ];
622
-
623
- parentTree.walk((childGroup) => {
624
- if (childGroup.excluded) {
625
- excludedItems = excludedItems.concat(childGroup.items);
626
- }
627
- }, false, false);
628
-
629
- dependantTrees.forEach((dependantTrees) => {
630
- dependantTrees.walk((childGroup) => {
631
- childGroup.setExcludedItems(excludedItems);
632
- }, false, false);
633
- });
634
- }
635
- }
636
- }));
637
- };
638
-
639
680
  compositeGroups.forEach((group) => {
640
- const childTree = currentTree.addChild(group);
641
-
642
- initializeGroupObservers(group, childTree);
681
+ const childTree = parentTree.addChild(group);
643
682
 
644
- addGroupBinding.call(this, group, group.registerMarketPercentChangeHandler(() => {
645
- currentTree.walk((childGroup) => childGroup.refreshMarketPercent());
646
- }));
683
+ initializeGroupObservers.call(this, childTree, treeDefinition);
647
684
 
648
- createGroups.call(this, parentTree, childTree, group.items, treeDefinition, array.dropLeft(levelDefinitions));
685
+ createGroups.call(this, childTree, group.items, treeDefinition, array.dropLeft(levelDefinitions));
649
686
  });
650
687
  }
651
688
 
@@ -747,7 +784,7 @@ module.exports = (() => {
747
784
  const displaySymbol = extractSymbolForDisplay(positionItem.position);
748
785
 
749
786
  if (this._symbolsDisplay.hasOwnProperty(displaySymbol)) {
750
- array.remove(this._symbols[displaySymbol], i => i === positionItem);
787
+ array.remove(this._symbolsDisplay[displaySymbol], i => i === positionItem);
751
788
  }
752
789
 
753
790
  const currency = extractCurrency(positionItem.position);
@@ -756,11 +793,13 @@ module.exports = (() => {
756
793
  array.remove(this._currencies[currency.code], i => i === positionItem);
757
794
  }
758
795
 
759
- this._trees[key].walk((group, groupNode) => {
760
- if (group.definition.type === PositionLevelType.POSITION && group.key === positionItem.position.position) {
761
- groupNode.sever();
762
- }
763
- }, true, false);
796
+ Object.keys(this._trees).forEach((key) => {
797
+ this._trees[key].walk((group, groupNode) => {
798
+ if (group.definition.type === PositionLevelType.POSITION && group.key === positionItem.position.position) {
799
+ groupNode.sever();
800
+ }
801
+ }, true, false);
802
+ });
764
803
 
765
804
  positionItem.dispose();
766
805
  }
@@ -329,12 +329,13 @@ module.exports = (() => {
329
329
  return this._excluded;
330
330
  }
331
331
 
332
- addItems(items) {
333
-
334
- this.refresh();
335
- }
336
-
337
- removeItems(items) {
332
+ /**
333
+ * Adds a new {@link PositionItem} to the group.
334
+ *
335
+ * @public
336
+ * @param {PositionItem} item
337
+ */
338
+ addItem(item) {
338
339
 
339
340
  this.refresh();
340
341
  }
@@ -240,7 +240,7 @@ module.exports = (() => {
240
240
  *
241
241
  * @public
242
242
  * @callback PositionLevelDefinition~keySelector
243
- * @param {PositionItem} session
243
+ * @param {PositionItem} item
244
244
  * @returns {String}
245
245
  */
246
246
 
@@ -250,7 +250,7 @@ module.exports = (() => {
250
250
  *
251
251
  * @public
252
252
  * @callback PositionLevelDefinition~descriptionSelector
253
- * @param {PositionItem} session
253
+ * @param {PositionItem} item
254
254
  * @returns {String}
255
255
  */
256
256
 
@@ -260,7 +260,7 @@ module.exports = (() => {
260
260
  *
261
261
  * @public
262
262
  * @callback PositionLevelDefinition~currencySelector
263
- * @param {PositionItem} session
263
+ * @param {PositionItem} item
264
264
  * @returns {Currency}
265
265
  */
266
266
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.176",
3
+ "version": "1.0.180",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -841,7 +841,7 @@ module.exports = (() => {
841
841
  this._trees = this._definitions.reduce((map, treeDefinition) => {
842
842
  const tree = new Tree();
843
843
 
844
- createGroups.call(this, tree, tree, this._items, treeDefinition, treeDefinition.definitions);
844
+ createGroups.call(this, tree, this._items, treeDefinition, treeDefinition.definitions);
845
845
 
846
846
  map[treeDefinition.name] = tree;
847
847
 
@@ -904,7 +904,7 @@ module.exports = (() => {
904
904
  const overrideRequiredGroups = [ portfolioRequiredGroup ];
905
905
 
906
906
  parentTrees.forEach((t) => {
907
- createGroups.call(this, tree, t, [ ], treeDefinition, levelDefinitions.slice(portfolioLevelDefinitionIndex), overrideRequiredGroups);
907
+ createGroups.call(this, t, [ ], treeDefinition, levelDefinitions.slice(portfolioLevelDefinitionIndex), overrideRequiredGroups);
908
908
  });
909
909
  }
910
910
  });
@@ -958,6 +958,41 @@ module.exports = (() => {
958
958
 
959
959
  this.startTransaction(() => {
960
960
  this.removePosition(position);
961
+
962
+ summaries.forEach((summary) => {
963
+ addSummaryCurrent(this._summariesCurrent, summary, this._currentSummaryFrame, this._currentSummaryRange);
964
+ addSummaryPrevious(this._summariesPrevious, summary, this._previousSummaryFrame, this._previousSummaryRanges);
965
+ });
966
+
967
+ const item = createPositionItem(position);
968
+
969
+ addBarchartSymbol(this._symbols, item);
970
+ addDisplaySymbol(this._symbolsDisplay, item);
971
+
972
+ this._items.push(item);
973
+
974
+ const createGroupOrInjectItem = (parentTree, treeDefinition, levelDefinitions) => {
975
+ const levelDefinition = levelDefinitions[0];
976
+ const levelKey = levelDefinition.keySelector(item);
977
+
978
+ let groupTree;
979
+
980
+ if (parentTree.getChildren().length > 0) {
981
+ groupTree = parentTree.getChildren().findChild(childGroup => childGroup.key === levelKey) || null;
982
+ } else {
983
+ groupTree = null;
984
+ }
985
+
986
+ if (groupTree !== null) {
987
+ groupTree.addItem(item);
988
+
989
+ createGroupOrInjectItem(groupTree, treeDefinition, array.dropLeft(levelDefinitions));
990
+ } else {
991
+ createGroups.call(this, parentTree, [ item ], treeDefinition, levelDefinitions, [ ]);
992
+ }
993
+ };
994
+
995
+ this._definitions.forEach(definition => createGroupOrInjectItem(this._trees[definition.name], definition, definition.definitions));
961
996
  });
962
997
  }
963
998
 
@@ -1121,7 +1156,7 @@ module.exports = (() => {
1121
1156
  *
1122
1157
  * @public
1123
1158
  * @param {String} name
1124
- * @param {Array.<String> keys
1159
+ * @param {Array.<String>} keys
1125
1160
  * @returns {PositionGroup}
1126
1161
  */
1127
1162
  getGroup(name, keys) {
@@ -1137,7 +1172,7 @@ module.exports = (() => {
1137
1172
  *
1138
1173
  * @public
1139
1174
  * @param {String} name
1140
- * @param {Array.<String> keys
1175
+ * @param {Array.<String>} keys
1141
1176
  * @returns {Array.<PositionGroup>}
1142
1177
  */
1143
1178
  getGroups(name, keys) {
@@ -1246,12 +1281,62 @@ module.exports = (() => {
1246
1281
  this._groupBindings[id].push(dispoable);
1247
1282
  }
1248
1283
 
1249
- function createGroups(parentTree, currentTree, items, treeDefinition, levelDefinitions, overrideRequiredGroups) {
1284
+ function initializeGroupObservers(groupTree, treeDefinition) {
1285
+ const group = groupTree.getValue();
1286
+
1287
+ addGroupBinding.call(this, group, group.registerGroupExcludedChangeHandler(() => {
1288
+ groupTree.climb((parentGroup, parentTree) => {
1289
+ if (parentGroup) {
1290
+ let excludedItems = [];
1291
+
1292
+ parentTree.walk((childGroup) => {
1293
+ if (childGroup.excluded) {
1294
+ excludedItems = excludedItems.concat(childGroup.items);
1295
+ }
1296
+ }, false, false);
1297
+
1298
+ parentGroup.setExcludedItems(array.unique(excludedItems));
1299
+ }
1300
+ }, false);
1301
+
1302
+ if (treeDefinition.exclusionDependencies.length > 0) {
1303
+ const dependantTrees = treeDefinition.exclusionDependencies.reduce((trees, name) => {
1304
+ if (this._trees.hasOwnProperty(name)) {
1305
+ trees.push(this._trees[name]);
1306
+ }
1307
+
1308
+ return trees;
1309
+ }, [ ]);
1310
+
1311
+ if (dependantTrees.length > 0) {
1312
+ let excludedItems = [ ];
1313
+
1314
+ groupTree.getRoot().walk((childGroup) => {
1315
+ if (childGroup.excluded) {
1316
+ excludedItems = excludedItems.concat(childGroup.items);
1317
+ }
1318
+ }, false, false);
1319
+
1320
+ dependantTrees.forEach((dependantTrees) => {
1321
+ dependantTrees.walk((childGroup) => {
1322
+ childGroup.setExcludedItems(excludedItems);
1323
+ }, false, false);
1324
+ });
1325
+ }
1326
+ }
1327
+ }));
1328
+
1329
+ addGroupBinding.call(this, group, group.registerMarketPercentChangeHandler(() => {
1330
+ groupTree.getParent().walk((childGroup) => childGroup.refreshMarketPercent());
1331
+ }));
1332
+ }
1333
+
1334
+ function createGroups(parentTree, items, treeDefinition, levelDefinitions, overrideRequiredGroups) {
1250
1335
  if (levelDefinitions.length === 0) {
1251
1336
  return;
1252
1337
  }
1253
1338
 
1254
- const parent = currentTree.getValue() || null;
1339
+ const parent = parentTree.getValue() || null;
1255
1340
 
1256
1341
  const levelDefinition = levelDefinitions[0];
1257
1342
 
@@ -1308,60 +1393,12 @@ module.exports = (() => {
1308
1393
 
1309
1394
  compositeGroups.sort(builder.toComparator());
1310
1395
 
1311
- const initializeGroupObservers = (group, groupTree) => {
1312
- addGroupBinding.call(this, group, group.registerGroupExcludedChangeHandler((excluded, sender) => {
1313
- groupTree.climb((parentGroup) => {
1314
- if (parentGroup) {
1315
- let excludedItems = [];
1316
-
1317
- currentTree.walk((childGroup) => {
1318
- if (childGroup.excluded) {
1319
- excludedItems = excludedItems.concat(childGroup.items);
1320
- }
1321
- }, false, false);
1322
-
1323
- parentGroup.setExcludedItems(array.unique(excludedItems));
1324
- }
1325
- }, false);
1326
-
1327
- if (treeDefinition.exclusionDependencies.length > 0) {
1328
- const dependantTrees = treeDefinition.exclusionDependencies.reduce((trees, name) => {
1329
- if (this._trees.hasOwnProperty(name)) {
1330
- trees.push(this._trees[name]);
1331
- }
1332
-
1333
- return trees;
1334
- }, [ ]);
1335
-
1336
- if (dependantTrees.length > 0) {
1337
- let excludedItems = [ ];
1338
-
1339
- parentTree.walk((childGroup) => {
1340
- if (childGroup.excluded) {
1341
- excludedItems = excludedItems.concat(childGroup.items);
1342
- }
1343
- }, false, false);
1344
-
1345
- dependantTrees.forEach((dependantTrees) => {
1346
- dependantTrees.walk((childGroup) => {
1347
- childGroup.setExcludedItems(excludedItems);
1348
- }, false, false);
1349
- });
1350
- }
1351
- }
1352
- }));
1353
- };
1354
-
1355
1396
  compositeGroups.forEach((group) => {
1356
- const childTree = currentTree.addChild(group);
1397
+ const childTree = parentTree.addChild(group);
1357
1398
 
1358
- initializeGroupObservers(group, childTree);
1399
+ initializeGroupObservers.call(this, childTree, treeDefinition);
1359
1400
 
1360
- addGroupBinding.call(this, group, group.registerMarketPercentChangeHandler(() => {
1361
- currentTree.walk((childGroup) => childGroup.refreshMarketPercent());
1362
- }));
1363
-
1364
- createGroups.call(this, parentTree, childTree, group.items, treeDefinition, array.dropLeft(levelDefinitions));
1401
+ createGroups.call(this, childTree, group.items, treeDefinition, array.dropLeft(levelDefinitions));
1365
1402
  });
1366
1403
  }
1367
1404
 
@@ -1463,7 +1500,7 @@ module.exports = (() => {
1463
1500
  const displaySymbol = extractSymbolForDisplay(positionItem.position);
1464
1501
 
1465
1502
  if (this._symbolsDisplay.hasOwnProperty(displaySymbol)) {
1466
- array.remove(this._symbols[displaySymbol], i => i === positionItem);
1503
+ array.remove(this._symbolsDisplay[displaySymbol], i => i === positionItem);
1467
1504
  }
1468
1505
 
1469
1506
  const currency = extractCurrency(positionItem.position);
@@ -1472,11 +1509,13 @@ module.exports = (() => {
1472
1509
  array.remove(this._currencies[currency.code], i => i === positionItem);
1473
1510
  }
1474
1511
 
1475
- this._trees[key].walk((group, groupNode) => {
1476
- if (group.definition.type === PositionLevelType.POSITION && group.key === positionItem.position.position) {
1477
- groupNode.sever();
1478
- }
1479
- }, true, false);
1512
+ Object.keys(this._trees).forEach((key) => {
1513
+ this._trees[key].walk((group, groupNode) => {
1514
+ if (group.definition.type === PositionLevelType.POSITION && group.key === positionItem.position.position) {
1515
+ groupNode.sever();
1516
+ }
1517
+ }, true, false);
1518
+ });
1480
1519
 
1481
1520
  positionItem.dispose();
1482
1521
  }
@@ -1816,12 +1855,13 @@ module.exports = (() => {
1816
1855
  return this._excluded;
1817
1856
  }
1818
1857
 
1819
- addItems(items) {
1820
-
1821
- this.refresh();
1822
- }
1823
-
1824
- removeItems(items) {
1858
+ /**
1859
+ * Adds a new {@link PositionItem} to the group.
1860
+ *
1861
+ * @public
1862
+ * @param {PositionItem} item
1863
+ */
1864
+ addItem(item) {
1825
1865
 
1826
1866
  this.refresh();
1827
1867
  }
@@ -2891,7 +2931,7 @@ module.exports = (() => {
2891
2931
  *
2892
2932
  * @public
2893
2933
  * @callback PositionLevelDefinition~keySelector
2894
- * @param {PositionItem} session
2934
+ * @param {PositionItem} item
2895
2935
  * @returns {String}
2896
2936
  */
2897
2937
 
@@ -2901,7 +2941,7 @@ module.exports = (() => {
2901
2941
  *
2902
2942
  * @public
2903
2943
  * @callback PositionLevelDefinition~descriptionSelector
2904
- * @param {PositionItem} session
2944
+ * @param {PositionItem} item
2905
2945
  * @returns {String}
2906
2946
  */
2907
2947
 
@@ -2911,7 +2951,7 @@ module.exports = (() => {
2911
2951
  *
2912
2952
  * @public
2913
2953
  * @callback PositionLevelDefinition~currencySelector
2914
- * @param {PositionItem} session
2954
+ * @param {PositionItem} item
2915
2955
  * @returns {Currency}
2916
2956
  */
2917
2957