@sumaris-net/ngx-components 1.23.26 → 1.23.27

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,15 +424,18 @@
424
424
  return rv;
425
425
  }, {});
426
426
  }
427
- function arrayDistinct(obj, properties) {
428
- if (isEmptyArray(obj))
429
- return obj;
430
- properties = properties || Object.keys(obj[0]);
427
+ function arrayDistinct(values, keyOrProperty) {
428
+ if (isEmptyArray(values))
429
+ 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, '|'); }));
431
434
  var existingIds = new Set();
432
- return obj.reduce(function (res, item) {
433
- var uniqueKey = joinPropertiesPath(item, properties, '|');
435
+ return values.reduce(function (res, item) {
436
+ var uniqueKey = computeKeyFn(item);
434
437
  if (existingIds.has(uniqueKey))
435
- return res; // Skip
438
+ return res; // Skip if duplicate
436
439
  existingIds.add(uniqueKey);
437
440
  return res.concat(item);
438
441
  }, []);