@whitesev/utils 2.3.1 → 2.3.2

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.
@@ -6444,13 +6444,29 @@ System.register('Utils', [], (function (exports) {
6444
6444
  * > ()=>{throw new Error('测试错误')}出现错误
6445
6445
  */
6446
6446
  tryCatch = TryCatch;
6447
- uniqueArray(uniqueArrayData = [], compareArrayData = [], compareFun = (item, item2) => {
6448
- // @ts-ignore
6447
+ uniqueArray(uniqueArrayData = [], compareArrayData, compareFun = (item, item2) => {
6449
6448
  return item === item2;
6450
6449
  }) {
6451
- return Array.from(uniqueArrayData).filter((item) => !Array.from(compareArrayData).some(function (item2) {
6452
- return compareFun(item, item2);
6453
- }));
6450
+ if (typeof compareArrayData === "function") {
6451
+ const compareFn = compareArrayData;
6452
+ const seen = new Set();
6453
+ const result = [];
6454
+ for (const item of uniqueArrayData) {
6455
+ // 使用compareFn函数来获取当前对象的唯一标识
6456
+ const identfier = compareFn(item);
6457
+ // 如果Set中还没有这个标识,则添加到结果数组中,并将其标识存入Set
6458
+ if (!seen.has(identfier)) {
6459
+ seen.add(identfier);
6460
+ result.push(item);
6461
+ }
6462
+ }
6463
+ return result;
6464
+ }
6465
+ else {
6466
+ return Array.from(uniqueArrayData).filter((item) => !Array.from(compareArrayData).some(function (item2) {
6467
+ return compareFun(item, item2);
6468
+ }));
6469
+ }
6454
6470
  }
6455
6471
  waitArrayLoopToEnd(data, handleFunc) {
6456
6472
  let UtilsContext = this;