@sumaris-net/ngx-components 1.23.27 → 1.23.28

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.
@@ -424,16 +424,21 @@
424
424
  return rv;
425
425
  }, {});
426
426
  }
427
- function arrayDistinct(values, keyOrProperty) {
427
+ /**
428
+ * Remove duplicated value, in array. Will compute a unique key (from given properties, or given function)
429
+ * @param values
430
+ * @param propertiesOrKeyFn
431
+ */
432
+ function arrayDistinct(values, propertiesOrKeyFn) {
428
433
  if (isEmptyArray(values))
429
434
  return values;
430
- var properties = Array.isArray(keyOrProperty) ? keyOrProperty : (!keyOrProperty && Object.keys(values[0]));
431
- var computeKeyFn = typeof keyOrProperty === 'function' ? keyOrProperty :
432
- (typeof keyOrProperty === 'string' ? (function (obj) { return getPropertyByPathAsString(obj, keyOrProperty); })
433
- : (function (obj) { return joinPropertiesPath(obj, properties, '|'); }));
435
+ var properties = (!propertiesOrKeyFn && Object.keys(values[0])) || (Array.isArray(propertiesOrKeyFn) && propertiesOrKeyFn);
436
+ var getKey = (typeof propertiesOrKeyFn === 'function' && propertiesOrKeyFn)
437
+ || (typeof propertiesOrKeyFn === 'string' && (function (obj) { return getPropertyByPathAsString(obj, propertiesOrKeyFn); }))
438
+ || (function (obj) { return joinPropertiesPath(obj, properties, '|'); });
434
439
  var existingIds = new Set();
435
440
  return values.reduce(function (res, item) {
436
- var uniqueKey = computeKeyFn(item);
441
+ var uniqueKey = getKey(item);
437
442
  if (existingIds.has(uniqueKey))
438
443
  return res; // Skip if duplicate
439
444
  existingIds.add(uniqueKey);