@sumaris-net/ngx-components 1.23.26 → 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,15 +424,23 @@
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
+ /**
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) {
433
+ if (isEmptyArray(values))
434
+ return values;
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, '|'); });
431
439
  var existingIds = new Set();
432
- return obj.reduce(function (res, item) {
433
- var uniqueKey = joinPropertiesPath(item, properties, '|');
440
+ return values.reduce(function (res, item) {
441
+ var uniqueKey = getKey(item);
434
442
  if (existingIds.has(uniqueKey))
435
- return res; // Skip
443
+ return res; // Skip if duplicate
436
444
  existingIds.add(uniqueKey);
437
445
  return res.concat(item);
438
446
  }, []);