cx 24.3.7 → 24.3.9

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.
package/dist/data.js CHANGED
@@ -156,12 +156,6 @@ function _setPrototypeOf(o, p) {
156
156
  };
157
157
  return _setPrototypeOf(o, p);
158
158
  }
159
- function _assertThisInitialized(self) {
160
- if (self === void 0) {
161
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
162
- }
163
- return self;
164
- }
165
159
 
166
160
  function computable() {
167
161
  var _ref;
@@ -222,8 +216,7 @@ function computable() {
222
216
  let e = Expression.compile('_.min({data})');
223
217
  */
224
218
 
225
- var expCache = {},
226
- helpers = {},
219
+ var helpers = {},
227
220
  helperNames = [],
228
221
  helperValues = [],
229
222
  expFatArrows = null;
@@ -287,7 +280,8 @@ function getExpr(expr) {
287
280
  }
288
281
  function expression(str) {
289
282
  if (isFunction(str)) return getExpr(str);
290
- var r = expCache[str];
283
+ var cache = getExpressionCache();
284
+ var r = cache[str];
291
285
  if (r) return r;
292
286
  var quote = false;
293
287
  var termStart = -1,
@@ -382,7 +376,7 @@ function expression(str) {
382
376
  })
383
377
  .concat([compute]),
384
378
  );
385
- expCache[str] = selector;
379
+ cache[str] = selector;
386
380
  return selector;
387
381
  } catch (err) {
388
382
  throw new Error("Failed to parse expression: '" + str + "'. Error: " + err.message);
@@ -409,12 +403,19 @@ function plugFatArrowExpansion(impl) {
409
403
  function invalidateExpressionCache() {
410
404
  expCache = {};
411
405
  }
406
+ var expCache = {};
407
+ var getExpressionCache = function getExpressionCache() {
408
+ return expCache;
409
+ };
410
+ function setGetExpressionCacheCallback(callback) {
411
+ getExpressionCache = callback;
412
+ }
412
413
 
413
414
  function plus(str) {
414
415
  return str.length ? str + " + " : str;
415
416
  }
416
- var tplCache = {};
417
417
  function stringTemplate(str) {
418
+ var tplCache = getTplCache();
418
419
  var expr = tplCache[str];
419
420
  if (expr) return expr;
420
421
  expr = "";
@@ -479,19 +480,26 @@ var StringTemplate = {
479
480
  return stringTemplate(_format)(args);
480
481
  },
481
482
  };
483
+ var tplCache = {};
484
+ var getTplCache = function getTplCache() {
485
+ return tplCache;
486
+ };
482
487
  function invalidateStringTemplateCache() {
483
488
  tplCache = {};
484
489
  }
490
+ function setGetStringTemplateCacheCallback(callback) {
491
+ getTplCache = callback;
492
+ }
485
493
 
486
494
  var Ref = /*#__PURE__*/ (function (_Component) {
487
- _inheritsLoose(Ref, _Component);
488
495
  function Ref(config) {
489
496
  var _this;
490
497
  _this = _Component.call(this, config) || this;
491
- _this.get = _this.get.bind(_assertThisInitialized(_this));
492
- if (_this.set) _this.set = _this.set.bind(_assertThisInitialized(_this));
498
+ _this.get = _this.get.bind(_this);
499
+ if (_this.set) _this.set = _this.set.bind(_this);
493
500
  return _this;
494
501
  }
502
+ _inheritsLoose(Ref, _Component);
495
503
  var _proto = Ref.prototype;
496
504
  _proto.get = function get() {
497
505
  throw new Error("Ref's get method is not implemented.");
@@ -549,13 +557,13 @@ Ref.factory = function (alias, config, more) {
549
557
  };
550
558
 
551
559
  var StoreRef = /*#__PURE__*/ (function (_Ref) {
552
- _inheritsLoose(StoreRef, _Ref);
553
560
  function StoreRef(config) {
554
561
  var _this;
555
562
  _this = _Ref.call(this, config) || this;
556
563
  if (isAccessorChain(_this.path)) _this.path = _this.path.toString();
557
564
  return _this;
558
565
  }
566
+ _inheritsLoose(StoreRef, _Ref);
559
567
  var _proto = StoreRef.prototype;
560
568
  _proto.get = function get() {
561
569
  return this.store.get(this.path);
@@ -761,7 +769,6 @@ View.prototype.mutate = function () {
761
769
  };
762
770
 
763
771
  var SubscribableView = /*#__PURE__*/ (function (_View) {
764
- _inheritsLoose(SubscribableView, _View);
765
772
  function SubscribableView(config) {
766
773
  var _this;
767
774
  _this = _View.call(this, config) || this;
@@ -769,6 +776,7 @@ var SubscribableView = /*#__PURE__*/ (function (_View) {
769
776
  _this.changes = [];
770
777
  return _this;
771
778
  }
779
+ _inheritsLoose(SubscribableView, _View);
772
780
  var _proto = SubscribableView.prototype;
773
781
  _proto.subscribe = function subscribe(callback) {
774
782
  return this.subscribers.subscribe(callback);
@@ -813,7 +821,6 @@ var SubscribableView = /*#__PURE__*/ (function (_View) {
813
821
  SubscribableView.prototype.async = false;
814
822
 
815
823
  var Store = /*#__PURE__*/ (function (_SubscribableView) {
816
- _inheritsLoose(Store, _SubscribableView);
817
824
  function Store(config) {
818
825
  var _this;
819
826
  if (config === void 0) {
@@ -826,6 +833,7 @@ var Store = /*#__PURE__*/ (function (_SubscribableView) {
826
833
  };
827
834
  return _this;
828
835
  }
836
+ _inheritsLoose(Store, _SubscribableView);
829
837
  var _proto = Store.prototype;
830
838
  _proto.getData = function getData() {
831
839
  return this.data;
@@ -860,10 +868,10 @@ var Store = /*#__PURE__*/ (function (_SubscribableView) {
860
868
  Store.prototype.async = false;
861
869
 
862
870
  var ExposedRecordView = /*#__PURE__*/ (function (_View) {
863
- _inheritsLoose(ExposedRecordView, _View);
864
871
  function ExposedRecordView() {
865
872
  return _View.apply(this, arguments) || this;
866
873
  }
874
+ _inheritsLoose(ExposedRecordView, _View);
867
875
  var _proto = ExposedRecordView.prototype;
868
876
  _proto.getData = function getData() {
869
877
  if (this.sealed && this.meta.version === this.cache.version && this.cache.itemIndex === this.itemIndex)
@@ -925,10 +933,10 @@ var ExposedRecordView = /*#__PURE__*/ (function (_View) {
925
933
  ExposedRecordView.prototype.immutable = false;
926
934
 
927
935
  var ExposedValueView = /*#__PURE__*/ (function (_View) {
928
- _inheritsLoose(ExposedValueView, _View);
929
936
  function ExposedValueView() {
930
937
  return _View.apply(this, arguments) || this;
931
938
  }
939
+ _inheritsLoose(ExposedValueView, _View);
932
940
  var _proto = ExposedValueView.prototype;
933
941
  _proto.getData = function getData() {
934
942
  if (this.sealed && this.meta.version === this.cache.version && this.cache.key === this.key)
@@ -987,10 +995,10 @@ var ExposedValueView = /*#__PURE__*/ (function (_View) {
987
995
  ExposedValueView.prototype.immutable = false;
988
996
 
989
997
  var ReadOnlyDataView = /*#__PURE__*/ (function (_View) {
990
- _inheritsLoose(ReadOnlyDataView, _View);
991
998
  function ReadOnlyDataView() {
992
999
  return _View.apply(this, arguments) || this;
993
1000
  }
1001
+ _inheritsLoose(ReadOnlyDataView, _View);
994
1002
  var _proto = ReadOnlyDataView.prototype;
995
1003
  _proto.getData = function getData() {
996
1004
  if (this.sealed && this.meta.version === this.cache.version && this.cache.data === this.data)
@@ -1015,10 +1023,10 @@ var ReadOnlyDataView = /*#__PURE__*/ (function (_View) {
1015
1023
  ReadOnlyDataView.prototype.immutable = false;
1016
1024
 
1017
1025
  var AugmentedViewBase = /*#__PURE__*/ (function (_View) {
1018
- _inheritsLoose(AugmentedViewBase, _View);
1019
1026
  function AugmentedViewBase() {
1020
1027
  return _View.apply(this, arguments) || this;
1021
1028
  }
1029
+ _inheritsLoose(AugmentedViewBase, _View);
1022
1030
  var _proto = AugmentedViewBase.prototype;
1023
1031
  _proto.getData = function getData() {
1024
1032
  if (this.meta.version === this.cache.version && this.sealed) return this.cache.result;
@@ -1077,10 +1085,10 @@ var AugmentedViewBase = /*#__PURE__*/ (function (_View) {
1077
1085
  AugmentedViewBase.prototype.immutable = false;
1078
1086
 
1079
1087
  var NestedDataView = /*#__PURE__*/ (function (_AugmentedViewBase) {
1080
- _inheritsLoose(NestedDataView, _AugmentedViewBase);
1081
1088
  function NestedDataView() {
1082
1089
  return _AugmentedViewBase.apply(this, arguments) || this;
1083
1090
  }
1091
+ _inheritsLoose(NestedDataView, _AugmentedViewBase);
1084
1092
  var _proto = NestedDataView.prototype;
1085
1093
  _proto.embedAugmentData = function embedAugmentData(result, parentStoreData) {
1086
1094
  if (this.nestedData) {
@@ -1101,10 +1109,10 @@ var NestedDataView = /*#__PURE__*/ (function (_AugmentedViewBase) {
1101
1109
  })(AugmentedViewBase);
1102
1110
 
1103
1111
  var ZoomIntoPropertyView = /*#__PURE__*/ (function (_NestedDataView) {
1104
- _inheritsLoose(ZoomIntoPropertyView, _NestedDataView);
1105
1112
  function ZoomIntoPropertyView() {
1106
1113
  return _NestedDataView.apply(this, arguments) || this;
1107
1114
  }
1115
+ _inheritsLoose(ZoomIntoPropertyView, _NestedDataView);
1108
1116
  var _proto = ZoomIntoPropertyView.prototype;
1109
1117
  _proto.getBaseData = function getBaseData(parentStoreData) {
1110
1118
  var x = this.binding.value(parentStoreData);
@@ -1503,17 +1511,28 @@ LastValue.prototype.result = null;
1503
1511
  }
1504
1512
  */
1505
1513
 
1506
- function transform(o, f) {
1507
- var res = {};
1508
- for (var k in o) res[k] = f(o[k], k);
1509
- return res;
1510
- }
1511
1514
  var Grouper = /*#__PURE__*/ (function () {
1512
1515
  function Grouper(key, aggregates, dataGetter, nameGetter) {
1513
- this.keys = Object.keys(key).map(function (k) {
1516
+ this.keys = Object.keys(key).map(function (keyField) {
1517
+ var isSimpleField = keyField.indexOf(".") === -1;
1518
+ var keySetter;
1519
+ if (isSimpleField) {
1520
+ // use simple field setter wherever possible
1521
+ keySetter = function set(result, value) {
1522
+ result[keyField] = value;
1523
+ return result;
1524
+ };
1525
+ } else {
1526
+ // for complex paths, use deep setter
1527
+ var binding = Binding.get(keyField);
1528
+ keySetter = function keySetter(result, value) {
1529
+ return binding.set(result, value);
1530
+ };
1531
+ }
1514
1532
  return {
1515
- name: k,
1516
- value: getSelector(key[k]),
1533
+ name: keyField,
1534
+ keySetter: keySetter,
1535
+ value: getSelector(key[keyField]),
1517
1536
  };
1518
1537
  });
1519
1538
  if (nameGetter) this.nameGetter = getSelector(nameGetter);
@@ -1524,11 +1543,12 @@ var Grouper = /*#__PURE__*/ (function () {
1524
1543
  };
1525
1544
  this.aggregates =
1526
1545
  aggregates &&
1527
- transform(aggregates, function (prop) {
1546
+ transformValues(aggregates, function (prop) {
1547
+ var _prop$weight;
1528
1548
  if (!AggregateFunction[prop.type]) throw new Error("Unknown aggregate function '" + prop.type + "'.");
1529
1549
  return {
1530
1550
  value: getSelector(prop.value),
1531
- weight: getSelector(prop.weight || 1),
1551
+ weight: getSelector((_prop$weight = prop.weight) != null ? _prop$weight : 1),
1532
1552
  type: prop.type,
1533
1553
  };
1534
1554
  });
@@ -1545,7 +1565,7 @@ var Grouper = /*#__PURE__*/ (function () {
1545
1565
  indexes: [],
1546
1566
  aggregates:
1547
1567
  this.aggregates &&
1548
- transform(this.aggregates, function (prop) {
1568
+ transformValues(this.aggregates, function (prop) {
1549
1569
  var f = AggregateFunction[prop.type];
1550
1570
  return {
1551
1571
  processor: f(),
@@ -1590,16 +1610,18 @@ var Grouper = /*#__PURE__*/ (function () {
1590
1610
  if (level == this.keys.length) {
1591
1611
  var key = {};
1592
1612
  this.keys.forEach(function (k, i) {
1593
- return (key[k.name] = path[i]);
1613
+ key = k.keySetter(key, path[i]);
1594
1614
  });
1595
1615
  results.push({
1596
1616
  key: key,
1597
1617
  name: g.name,
1598
1618
  records: g.records,
1599
1619
  indexes: g.indexes,
1600
- aggregates: transform(g.aggregates, function (p) {
1601
- return p.processor.getResult();
1602
- }),
1620
+ aggregates: resolveKeyPaths(
1621
+ transformValues(g.aggregates, function (p) {
1622
+ return p.processor.getResult();
1623
+ }),
1624
+ ),
1603
1625
  });
1604
1626
  } else {
1605
1627
  Object.keys(g).forEach(function (k) {
@@ -1616,6 +1638,23 @@ var Grouper = /*#__PURE__*/ (function () {
1616
1638
  return Grouper;
1617
1639
  })();
1618
1640
 
1641
+ // transform object values using a function
1642
+ function transformValues(o, f) {
1643
+ var res = {};
1644
+ for (var k in o) res[k] = f(o[k], k);
1645
+ return res;
1646
+ }
1647
+
1648
+ // transform keys like 'a.b.c' into nested objects
1649
+ function resolveKeyPaths(o) {
1650
+ var res = {};
1651
+ for (var k in o) {
1652
+ if (k.indexOf(".") > 0) res = Binding.get(k).set(res, o[k]);
1653
+ else res[k] = o[k];
1654
+ }
1655
+ return res;
1656
+ }
1657
+
1619
1658
  function defaultCompare(av, bv) {
1620
1659
  if (av == null) {
1621
1660
  if (bv == null) return 0;
@@ -1858,10 +1897,10 @@ function diffArrays(oldArray, newArray, keyFn) {
1858
1897
  }
1859
1898
 
1860
1899
  var ArrayRef = /*#__PURE__*/ (function (_Ref) {
1861
- _inheritsLoose(ArrayRef, _Ref);
1862
1900
  function ArrayRef() {
1863
1901
  return _Ref.apply(this, arguments) || this;
1864
1902
  }
1903
+ _inheritsLoose(ArrayRef, _Ref);
1865
1904
  var _proto = ArrayRef.prototype;
1866
1905
  _proto.append = function append$1() {
1867
1906
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
@@ -1899,18 +1938,18 @@ var ArrayRef = /*#__PURE__*/ (function (_Ref) {
1899
1938
  })(Ref);
1900
1939
 
1901
1940
  var StoreProxy = /*#__PURE__*/ (function (_View) {
1902
- _inheritsLoose(StoreProxy, _View);
1903
1941
  function StoreProxy(getStore) {
1904
1942
  var _this;
1905
1943
  _this =
1906
1944
  _View.call(this, {
1907
1945
  store: getStore(),
1908
1946
  }) || this;
1909
- Object.defineProperty(_assertThisInitialized(_this), "store", {
1947
+ Object.defineProperty(_this, "store", {
1910
1948
  get: getStore,
1911
1949
  });
1912
1950
  return _this;
1913
1951
  }
1952
+ _inheritsLoose(StoreProxy, _View);
1914
1953
  var _proto = StoreProxy.prototype;
1915
1954
  _proto.getData = function getData() {
1916
1955
  return this.store.getData();
@@ -1919,10 +1958,10 @@ var StoreProxy = /*#__PURE__*/ (function (_View) {
1919
1958
  })(View);
1920
1959
 
1921
1960
  var ArrayElementView = /*#__PURE__*/ (function (_AugmentedViewBase) {
1922
- _inheritsLoose(ArrayElementView, _AugmentedViewBase);
1923
1961
  function ArrayElementView() {
1924
1962
  return _AugmentedViewBase.apply(this, arguments) || this;
1925
1963
  }
1964
+ _inheritsLoose(ArrayElementView, _AugmentedViewBase);
1926
1965
  var _proto = ArrayElementView.prototype;
1927
1966
  _proto.isExtraKey = function isExtraKey(key) {
1928
1967
  return key == this.recordAlias || key == this.indexAlias || key == this.lengthAlias;
@@ -2059,6 +2098,8 @@ export {
2059
2098
  moveElement,
2060
2099
  plugFatArrowExpansion,
2061
2100
  removeTreeNodes,
2101
+ setGetExpressionCacheCallback,
2102
+ setGetStringTemplateCacheCallback,
2062
2103
  sorter,
2063
2104
  stringTemplate,
2064
2105
  updateArray,