@flowlist/js-core 4.0.4-beta.0 → 4.0.5-beta.0
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/index.d.mts +114 -154
- package/dist/index.d.ts +114 -154
- package/dist/index.global.js +144 -215
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +144 -215
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +144 -216
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.global.js
CHANGED
|
@@ -51,25 +51,27 @@ var FlowList = (function (exports) {
|
|
|
51
51
|
generateFieldName: () => generateFieldName,
|
|
52
52
|
generateRequestParams: () => generateRequestParams,
|
|
53
53
|
getObjectDeepValue: () => getObjectDeepValue,
|
|
54
|
+
getResultAsArray: () => getResultAsArray,
|
|
54
55
|
isArray: () => isArray,
|
|
55
56
|
isKeyMap: () => isKeyMap,
|
|
56
57
|
isKeyMapArray: () => isKeyMapArray,
|
|
57
58
|
isObjectKey: () => isObjectKey,
|
|
58
59
|
isObjectKeyArray: () => isObjectKeyArray,
|
|
59
60
|
isObjectResult: () => isObjectResult,
|
|
60
|
-
isResultArray: () => isResultArray,
|
|
61
61
|
isResultObject: () => isResultObject,
|
|
62
62
|
searchValueByKey: () => searchValueByKey,
|
|
63
63
|
setReactivityField: () => setReactivityField,
|
|
64
|
+
stableSerialize: () => stableSerialize,
|
|
65
|
+
toObjectKey: () => toObjectKey,
|
|
66
|
+
updateArrayItem: () => updateArrayItem,
|
|
64
67
|
updateObjectDeepValue: () => updateObjectDeepValue
|
|
65
68
|
});
|
|
66
69
|
var isArray = (data) => Array.isArray(data);
|
|
67
|
-
var
|
|
68
|
-
var isResultObject = (data) => !Array.isArray(data) && typeof data === "object" && data !== null;
|
|
70
|
+
var isResultObject = (data) => !isArray(data) && typeof data === "object" && data !== null;
|
|
69
71
|
var isObjectKey = (value) => typeof value === "string" || typeof value === "number";
|
|
70
|
-
var isKeyMap = (value) => typeof value === "object" && value !== null && !
|
|
71
|
-
var isKeyMapArray = (value) =>
|
|
72
|
-
var isObjectKeyArray = (value) =>
|
|
72
|
+
var isKeyMap = (value) => typeof value === "object" && value !== null && !isArray(value);
|
|
73
|
+
var isKeyMapArray = (value) => isArray(value) && value.every((item) => typeof item === "object" && item !== null);
|
|
74
|
+
var isObjectKeyArray = (value) => isArray(value) && value.every((item) => typeof item === "string" || typeof item === "number");
|
|
73
75
|
var stableSerialize = (value) => {
|
|
74
76
|
if (value === null || typeof value !== "object") {
|
|
75
77
|
return String(value);
|
|
@@ -115,6 +117,7 @@ var FlowList = (function (exports) {
|
|
|
115
117
|
};
|
|
116
118
|
var generateDefaultField = (opts = {}) => ({
|
|
117
119
|
result: [],
|
|
120
|
+
// 默认为空数组,但强制转换为泛型 T
|
|
118
121
|
noMore: false,
|
|
119
122
|
nothing: false,
|
|
120
123
|
loading: false,
|
|
@@ -161,11 +164,7 @@ var FlowList = (function (exports) {
|
|
|
161
164
|
if (result == null || typeof result !== "object") {
|
|
162
165
|
return void 0;
|
|
163
166
|
}
|
|
164
|
-
|
|
165
|
-
result = result[keysArr[i]];
|
|
166
|
-
} else {
|
|
167
|
-
return void 0;
|
|
168
|
-
}
|
|
167
|
+
result = result[keysArr[i]];
|
|
169
168
|
}
|
|
170
169
|
return result;
|
|
171
170
|
};
|
|
@@ -194,7 +193,7 @@ var FlowList = (function (exports) {
|
|
|
194
193
|
}
|
|
195
194
|
};
|
|
196
195
|
var searchValueByKey = (result, id, key) => {
|
|
197
|
-
if (
|
|
196
|
+
if (isArray(result)) {
|
|
198
197
|
const index = computeMatchedItemIndex(id, result, key);
|
|
199
198
|
return index >= 0 ? result[index] : void 0;
|
|
200
199
|
}
|
|
@@ -258,18 +257,19 @@ var FlowList = (function (exports) {
|
|
|
258
257
|
}
|
|
259
258
|
};
|
|
260
259
|
var setReactivityField = (field, key, value, type, insertBefore) => {
|
|
260
|
+
const fieldAny = field;
|
|
261
261
|
if (type === enum_default.FETCH_TYPE.PAGINATION) {
|
|
262
|
-
|
|
262
|
+
fieldAny[key] = value;
|
|
263
263
|
return;
|
|
264
264
|
}
|
|
265
265
|
if (key !== enum_default.FIELD_DATA.RESULT_KEY) {
|
|
266
266
|
if (isArray(value)) {
|
|
267
|
-
const current =
|
|
267
|
+
const current = fieldAny[key];
|
|
268
268
|
const currentArr = isArray(current) ? current : [];
|
|
269
269
|
const newValue = insertBefore ? [...value, ...currentArr] : [...currentArr, ...value];
|
|
270
|
-
|
|
270
|
+
fieldAny[key] = newValue;
|
|
271
271
|
} else {
|
|
272
|
-
|
|
272
|
+
fieldAny[key] = value;
|
|
273
273
|
}
|
|
274
274
|
return;
|
|
275
275
|
}
|
|
@@ -277,24 +277,21 @@ var FlowList = (function (exports) {
|
|
|
277
277
|
const valueObj = value;
|
|
278
278
|
if (isArray(value)) {
|
|
279
279
|
const currentArr = isArray(resultField) ? resultField : [];
|
|
280
|
+
const valueArr = value;
|
|
280
281
|
if (insertBefore) {
|
|
281
|
-
if (
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
282
|
+
if (valueArr.length === 0) return;
|
|
284
283
|
if (currentArr.length === 0) {
|
|
285
|
-
field.result =
|
|
284
|
+
field.result = valueArr;
|
|
286
285
|
return;
|
|
287
286
|
}
|
|
288
|
-
field.result =
|
|
287
|
+
field.result = valueArr.concat(currentArr);
|
|
289
288
|
} else {
|
|
290
|
-
if (
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
289
|
+
if (valueArr.length === 0) return;
|
|
293
290
|
if (currentArr.length === 0) {
|
|
294
|
-
field.result =
|
|
291
|
+
field.result = valueArr;
|
|
295
292
|
return;
|
|
296
293
|
}
|
|
297
|
-
field.result = currentArr.concat(
|
|
294
|
+
field.result = currentArr.concat(valueArr);
|
|
298
295
|
}
|
|
299
296
|
return;
|
|
300
297
|
}
|
|
@@ -361,27 +358,28 @@ var FlowList = (function (exports) {
|
|
|
361
358
|
}) => {
|
|
362
359
|
const result = { ...query };
|
|
363
360
|
const isFetched = field.fetched;
|
|
361
|
+
const fieldResultAny = field.result;
|
|
364
362
|
const getSafeObjectKey = (item) => {
|
|
365
363
|
return extractUniqueKey(item, uniqueKey);
|
|
366
364
|
};
|
|
367
365
|
if (isFetched) {
|
|
368
366
|
if (type === enum_default.FETCH_TYPE.AUTO) {
|
|
369
|
-
if (
|
|
370
|
-
result.seen_ids = getSeenIdsString(
|
|
371
|
-
const targetIndex = query.is_up ? 0 :
|
|
372
|
-
const targetItem =
|
|
367
|
+
if (isArray(fieldResultAny)) {
|
|
368
|
+
result.seen_ids = getSeenIdsString(fieldResultAny, uniqueKey);
|
|
369
|
+
const targetIndex = query.is_up ? 0 : fieldResultAny.length - 1;
|
|
370
|
+
const targetItem = fieldResultAny[targetIndex];
|
|
373
371
|
result.since_id = getSafeObjectKey(targetItem);
|
|
374
372
|
}
|
|
375
373
|
result.is_up = query.is_up ? 1 : 0;
|
|
376
374
|
result.page = typeof query.page === "number" ? query.page : field.page + 1;
|
|
377
375
|
} else if (type === enum_default.FETCH_TYPE.HAS_LOADED_IDS) {
|
|
378
|
-
if (
|
|
379
|
-
result.seen_ids = getSeenIdsString(
|
|
376
|
+
if (isArray(fieldResultAny)) {
|
|
377
|
+
result.seen_ids = getSeenIdsString(fieldResultAny, uniqueKey);
|
|
380
378
|
}
|
|
381
379
|
} else if (type === enum_default.FETCH_TYPE.SINCE_FIRST_OR_END_ID) {
|
|
382
|
-
if (
|
|
383
|
-
const targetIndex = query.is_up ? 0 :
|
|
384
|
-
const targetItem =
|
|
380
|
+
if (isArray(fieldResultAny)) {
|
|
381
|
+
const targetIndex = query.is_up ? 0 : fieldResultAny.length - 1;
|
|
382
|
+
const targetItem = fieldResultAny[targetIndex];
|
|
385
383
|
result.since_id = getSafeObjectKey(targetItem);
|
|
386
384
|
}
|
|
387
385
|
result.is_up = query.is_up ? 1 : 0;
|
|
@@ -409,6 +407,24 @@ var FlowList = (function (exports) {
|
|
|
409
407
|
}
|
|
410
408
|
return result;
|
|
411
409
|
};
|
|
410
|
+
var toObjectKey = (id) => {
|
|
411
|
+
if (id === void 0) return void 0;
|
|
412
|
+
if (isObjectKey(id)) return id;
|
|
413
|
+
if (isObjectKeyArray(id) && id.length > 0) return id[0];
|
|
414
|
+
return void 0;
|
|
415
|
+
};
|
|
416
|
+
var getResultAsArray = (field) => {
|
|
417
|
+
const result = field[enum_default.FIELD_DATA.RESULT_KEY];
|
|
418
|
+
return isArray(result) ? result : null;
|
|
419
|
+
};
|
|
420
|
+
var updateArrayItem = (arr, index, updater) => {
|
|
421
|
+
if (index >= 0 && index < arr.length) {
|
|
422
|
+
const item = arr[index];
|
|
423
|
+
if (isKeyMap(item)) {
|
|
424
|
+
arr[index] = updater(item);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
};
|
|
412
428
|
|
|
413
429
|
// src/setters.ts
|
|
414
430
|
var SET_DATA = ({
|
|
@@ -498,7 +514,7 @@ var FlowList = (function (exports) {
|
|
|
498
514
|
opts
|
|
499
515
|
}) => {
|
|
500
516
|
return new Promise((resolve) => {
|
|
501
|
-
const fieldName =
|
|
517
|
+
const fieldName = generateFieldName2({ func, query });
|
|
502
518
|
const fieldData = getter(fieldName);
|
|
503
519
|
if (fieldData) {
|
|
504
520
|
resolve();
|
|
@@ -521,19 +537,23 @@ var FlowList = (function (exports) {
|
|
|
521
537
|
query,
|
|
522
538
|
callback
|
|
523
539
|
}) => new Promise((resolve, reject) => {
|
|
524
|
-
const fieldName =
|
|
540
|
+
const fieldName = generateFieldName2({ func, query });
|
|
525
541
|
const fieldData = getter(fieldName);
|
|
526
|
-
const
|
|
527
|
-
const
|
|
528
|
-
const
|
|
542
|
+
const doRefresh = !!query?.__refresh__;
|
|
543
|
+
const needReset = !!query?.__reload__;
|
|
544
|
+
const directlyLoadData = doRefresh && !needReset;
|
|
545
|
+
if (fieldData && fieldData.error && !doRefresh) return resolve();
|
|
529
546
|
if (fieldData && fieldData.loading) return resolve();
|
|
530
547
|
if (fieldData && fieldData.fetched && !doRefresh) return resolve();
|
|
531
548
|
const params = generateRequestParams({
|
|
532
|
-
field:
|
|
549
|
+
field: generateDefaultField({
|
|
550
|
+
...fieldData,
|
|
551
|
+
fetched: false
|
|
552
|
+
}),
|
|
533
553
|
uniqueKey: func.uniqueKey,
|
|
534
|
-
// 自动从契约获取
|
|
535
554
|
type: func.type,
|
|
536
555
|
query
|
|
556
|
+
// 内部生成逻辑兼容
|
|
537
557
|
});
|
|
538
558
|
const executeFetch = () => {
|
|
539
559
|
func(params).then((data) => {
|
|
@@ -555,7 +575,7 @@ var FlowList = (function (exports) {
|
|
|
555
575
|
resolve();
|
|
556
576
|
});
|
|
557
577
|
};
|
|
558
|
-
if (
|
|
578
|
+
if (directlyLoadData) {
|
|
559
579
|
setter({
|
|
560
580
|
key: fieldName,
|
|
561
581
|
type: enum_default.SETTER_TYPE.RESET,
|
|
@@ -570,16 +590,20 @@ var FlowList = (function (exports) {
|
|
|
570
590
|
reject(error);
|
|
571
591
|
});
|
|
572
592
|
};
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
593
|
+
if (directlyLoadData) {
|
|
594
|
+
executeFetch();
|
|
595
|
+
} else {
|
|
596
|
+
setter({
|
|
597
|
+
key: fieldName,
|
|
598
|
+
type: enum_default.SETTER_TYPE.RESET,
|
|
599
|
+
value: {
|
|
600
|
+
...generateDefaultField(),
|
|
601
|
+
loading: true,
|
|
602
|
+
error: null
|
|
603
|
+
},
|
|
604
|
+
callback: executeFetch
|
|
605
|
+
});
|
|
606
|
+
}
|
|
583
607
|
});
|
|
584
608
|
var loadMore = ({
|
|
585
609
|
getter,
|
|
@@ -589,34 +613,52 @@ var FlowList = (function (exports) {
|
|
|
589
613
|
errorRetry,
|
|
590
614
|
callback
|
|
591
615
|
}) => new Promise((resolve, reject) => {
|
|
592
|
-
const fieldName =
|
|
616
|
+
const fieldName = generateFieldName2({ func, query });
|
|
593
617
|
const fieldData = getter(fieldName);
|
|
618
|
+
const type = func.type;
|
|
594
619
|
if (!fieldData || fieldData.loading || fieldData.nothing) return resolve();
|
|
595
620
|
if (fieldData.noMore && !errorRetry) return resolve();
|
|
621
|
+
if (type === enum_default.FETCH_TYPE.PAGINATION && query && query.page != null && Number(query.page) === fieldData.page) {
|
|
622
|
+
resolve();
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
let loadingState;
|
|
626
|
+
if (type === enum_default.FETCH_TYPE.PAGINATION) {
|
|
627
|
+
loadingState = {
|
|
628
|
+
loading: true,
|
|
629
|
+
error: null,
|
|
630
|
+
[enum_default.FIELD_DATA.RESULT_KEY]: [],
|
|
631
|
+
[enum_default.FIELD_DATA.EXTRA_KEY]: null
|
|
632
|
+
};
|
|
633
|
+
} else {
|
|
634
|
+
loadingState = {
|
|
635
|
+
loading: true,
|
|
636
|
+
error: null
|
|
637
|
+
};
|
|
638
|
+
}
|
|
596
639
|
const params = generateRequestParams({
|
|
597
640
|
field: fieldData,
|
|
598
641
|
uniqueKey: func.uniqueKey,
|
|
599
|
-
type
|
|
642
|
+
type,
|
|
600
643
|
query
|
|
601
644
|
});
|
|
602
645
|
if (fieldData.extra) {
|
|
603
646
|
params[enum_default.FIELD_DATA.EXTRA_KEY] = fieldData.extra;
|
|
604
647
|
}
|
|
605
|
-
const queryAsParams = query;
|
|
606
648
|
setter({
|
|
607
649
|
key: fieldName,
|
|
608
650
|
type: enum_default.SETTER_TYPE.MERGE,
|
|
609
|
-
value:
|
|
651
|
+
value: loadingState,
|
|
610
652
|
callback: () => {
|
|
611
653
|
func(params).then((data) => {
|
|
612
654
|
SET_DATA({
|
|
613
655
|
getter,
|
|
614
656
|
setter,
|
|
615
657
|
data,
|
|
658
|
+
type,
|
|
616
659
|
fieldName,
|
|
617
|
-
type: func.type,
|
|
618
660
|
page: params.page || 0,
|
|
619
|
-
insertBefore: !!
|
|
661
|
+
insertBefore: !!query?.is_up
|
|
620
662
|
}).then(() => {
|
|
621
663
|
callback?.({
|
|
622
664
|
params,
|
|
@@ -632,24 +674,6 @@ var FlowList = (function (exports) {
|
|
|
632
674
|
}
|
|
633
675
|
});
|
|
634
676
|
});
|
|
635
|
-
var toObjectKey = (id) => {
|
|
636
|
-
if (id === void 0) return void 0;
|
|
637
|
-
if (isObjectKey(id)) return id;
|
|
638
|
-
if (isObjectKeyArray(id) && id.length > 0) return id[0];
|
|
639
|
-
return void 0;
|
|
640
|
-
};
|
|
641
|
-
var getResultAsArray = (field) => {
|
|
642
|
-
const result = field[enum_default.FIELD_DATA.RESULT_KEY];
|
|
643
|
-
return isResultArray(result) ? result : null;
|
|
644
|
-
};
|
|
645
|
-
var updateArrayItem = (arr, index, updater) => {
|
|
646
|
-
if (index >= 0 && index < arr.length) {
|
|
647
|
-
const item = arr[index];
|
|
648
|
-
if (isKeyMap(item)) {
|
|
649
|
-
arr[index] = updater(item);
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
};
|
|
653
677
|
var updateState = ({
|
|
654
678
|
getter,
|
|
655
679
|
setter,
|
|
@@ -661,7 +685,7 @@ var FlowList = (function (exports) {
|
|
|
661
685
|
changeKey
|
|
662
686
|
}) => {
|
|
663
687
|
return new Promise((resolve, reject) => {
|
|
664
|
-
const fieldName =
|
|
688
|
+
const fieldName = generateFieldName2({ func, query });
|
|
665
689
|
const fieldData = getter(fieldName);
|
|
666
690
|
if (!fieldData) {
|
|
667
691
|
reject(new Error(`Field ${fieldName} not found.`));
|
|
@@ -673,7 +697,7 @@ var FlowList = (function (exports) {
|
|
|
673
697
|
}
|
|
674
698
|
const _id = id;
|
|
675
699
|
const _uniqueKey = func.uniqueKey || enum_default.DEFAULT_UNIQUE_KEY_NAME;
|
|
676
|
-
|
|
700
|
+
changeKey || enum_default.FIELD_DATA.RESULT_KEY;
|
|
677
701
|
const beforeLength = computeResultLength(
|
|
678
702
|
fieldData[enum_default.FIELD_DATA.RESULT_KEY]
|
|
679
703
|
);
|
|
@@ -688,121 +712,6 @@ var FlowList = (function (exports) {
|
|
|
688
712
|
const searchResult = resultArray ? searchValueByKey(resultArray, objectKeyId, _uniqueKey) : void 0;
|
|
689
713
|
resolve(searchResult);
|
|
690
714
|
return;
|
|
691
|
-
} else if (method === enum_default.CHANGE_TYPE.RESULT_UPDATE_KV) {
|
|
692
|
-
const objectKeyId = toObjectKey(_id);
|
|
693
|
-
if (objectKeyId === void 0) {
|
|
694
|
-
reject(new Error("ID is required for RESULT_UPDATE_KV."));
|
|
695
|
-
return;
|
|
696
|
-
}
|
|
697
|
-
if (resultArray) {
|
|
698
|
-
const matchedIndex = computeMatchedItemIndex(
|
|
699
|
-
objectKeyId,
|
|
700
|
-
resultArray,
|
|
701
|
-
_uniqueKey
|
|
702
|
-
);
|
|
703
|
-
if (matchedIndex >= 0 && isKeyMap(resultArray[matchedIndex])) {
|
|
704
|
-
updateObjectDeepValue(resultArray[matchedIndex], _changeKey, value);
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
resolve(null);
|
|
708
|
-
} else if (method === enum_default.CHANGE_TYPE.RESULT_ITEM_MERGE) {
|
|
709
|
-
const objectKeyId = toObjectKey(_id);
|
|
710
|
-
if (objectKeyId === void 0) {
|
|
711
|
-
reject(new Error("ID is required for RESULT_ITEM_MERGE."));
|
|
712
|
-
return;
|
|
713
|
-
}
|
|
714
|
-
if (resultArray && isKeyMap(value)) {
|
|
715
|
-
const matchedIndex = computeMatchedItemIndex(
|
|
716
|
-
objectKeyId,
|
|
717
|
-
resultArray,
|
|
718
|
-
_uniqueKey
|
|
719
|
-
);
|
|
720
|
-
updateArrayItem(resultArray, matchedIndex, (item) => ({
|
|
721
|
-
...item,
|
|
722
|
-
...value
|
|
723
|
-
}));
|
|
724
|
-
}
|
|
725
|
-
resolve(null);
|
|
726
|
-
} else if (method === enum_default.CHANGE_TYPE.RESET_FIELD) {
|
|
727
|
-
if (_changeKey === enum_default.FIELD_DATA.RESULT_KEY && isKeyMapArray(value)) {
|
|
728
|
-
newFieldData.result = value;
|
|
729
|
-
} else if (_changeKey === enum_default.FIELD_DATA.EXTRA_KEY && isKeyMap(value)) {
|
|
730
|
-
newFieldData.extra = value;
|
|
731
|
-
}
|
|
732
|
-
resolve(null);
|
|
733
|
-
} else {
|
|
734
|
-
let modifyValue;
|
|
735
|
-
if (_changeKey === enum_default.FIELD_DATA.RESULT_KEY) {
|
|
736
|
-
modifyValue = newFieldData.result;
|
|
737
|
-
} else if (_changeKey === enum_default.FIELD_DATA.EXTRA_KEY) {
|
|
738
|
-
modifyValue = newFieldData.extra;
|
|
739
|
-
} else {
|
|
740
|
-
modifyValue = getObjectDeepValue(newFieldData, _changeKey);
|
|
741
|
-
}
|
|
742
|
-
if (modifyValue == null) {
|
|
743
|
-
modifyValue = [];
|
|
744
|
-
}
|
|
745
|
-
const objectKeyId = toObjectKey(_id);
|
|
746
|
-
const matchedIndex = objectKeyId !== void 0 && isKeyMapArray(modifyValue) ? computeMatchedItemIndex(objectKeyId, modifyValue, _uniqueKey) : -1;
|
|
747
|
-
switch (method) {
|
|
748
|
-
case enum_default.CHANGE_TYPE.RESULT_ADD_AFTER:
|
|
749
|
-
if (isArray(modifyValue)) {
|
|
750
|
-
modifyValue = isArray(value) ? [...modifyValue, ...value] : [...modifyValue, value];
|
|
751
|
-
}
|
|
752
|
-
break;
|
|
753
|
-
case enum_default.CHANGE_TYPE.RESULT_ADD_BEFORE:
|
|
754
|
-
if (isArray(modifyValue)) {
|
|
755
|
-
modifyValue = isArray(value) ? [...value, ...modifyValue] : [value, ...modifyValue];
|
|
756
|
-
}
|
|
757
|
-
break;
|
|
758
|
-
case enum_default.CHANGE_TYPE.RESULT_REMOVE_BY_ID:
|
|
759
|
-
if (isKeyMapArray(modifyValue)) {
|
|
760
|
-
if (matchedIndex >= 0) {
|
|
761
|
-
modifyValue.splice(matchedIndex, 1);
|
|
762
|
-
} else if (isObjectKeyArray(_id)) {
|
|
763
|
-
const idSet = new Set(_id);
|
|
764
|
-
modifyValue = modifyValue.filter((item) => {
|
|
765
|
-
const itemKey = getObjectDeepValue(item, _uniqueKey);
|
|
766
|
-
return !isObjectKey(itemKey) || !idSet.has(itemKey);
|
|
767
|
-
});
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
break;
|
|
771
|
-
case enum_default.CHANGE_TYPE.RESULT_INSERT_TO_BEFORE:
|
|
772
|
-
if (isArray(modifyValue) && matchedIndex >= 0) {
|
|
773
|
-
modifyValue.splice(matchedIndex, 0, value);
|
|
774
|
-
}
|
|
775
|
-
break;
|
|
776
|
-
case enum_default.CHANGE_TYPE.RESULT_INSERT_TO_AFTER:
|
|
777
|
-
if (isArray(modifyValue) && matchedIndex >= 0) {
|
|
778
|
-
modifyValue.splice(matchedIndex + 1, 0, value);
|
|
779
|
-
}
|
|
780
|
-
break;
|
|
781
|
-
case enum_default.CHANGE_TYPE.RESULT_LIST_MERGE:
|
|
782
|
-
if (isKeyMapArray(modifyValue)) {
|
|
783
|
-
if (isKeyMapArray(value)) {
|
|
784
|
-
combineArrayData(modifyValue, value, _uniqueKey);
|
|
785
|
-
} else if (isKeyMap(value)) {
|
|
786
|
-
const valueAsRecord = {};
|
|
787
|
-
for (const [k, v] of Object.entries(value)) {
|
|
788
|
-
if (isKeyMap(v)) {
|
|
789
|
-
valueAsRecord[k] = v;
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
combineArrayData(modifyValue, valueAsRecord, _uniqueKey);
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
break;
|
|
796
|
-
default:
|
|
797
|
-
resolve(null);
|
|
798
|
-
return;
|
|
799
|
-
}
|
|
800
|
-
if (_changeKey === enum_default.FIELD_DATA.RESULT_KEY && isKeyMapArray(modifyValue)) {
|
|
801
|
-
newFieldData.result = modifyValue;
|
|
802
|
-
} else if (_changeKey === enum_default.FIELD_DATA.EXTRA_KEY && isKeyMap(modifyValue)) {
|
|
803
|
-
newFieldData.extra = modifyValue;
|
|
804
|
-
}
|
|
805
|
-
resolve(null);
|
|
806
715
|
}
|
|
807
716
|
const afterLength = computeResultLength(
|
|
808
717
|
newFieldData[enum_default.FIELD_DATA.RESULT_KEY]
|
|
@@ -819,31 +728,51 @@ var FlowList = (function (exports) {
|
|
|
819
728
|
});
|
|
820
729
|
});
|
|
821
730
|
};
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
731
|
+
var createApi = (options) => {
|
|
732
|
+
const fn = (params) => options.fetcher(params);
|
|
733
|
+
fn.id = options.id;
|
|
734
|
+
fn.type = options.type || enum_default.FETCH_TYPE.SCROLL_LOAD_MORE;
|
|
735
|
+
fn.uniqueKey = options.uniqueKey || enum_default.DEFAULT_UNIQUE_KEY_NAME;
|
|
736
|
+
fn.paramsIgnore = [
|
|
737
|
+
"page",
|
|
738
|
+
"is_up",
|
|
739
|
+
"since_id",
|
|
740
|
+
"seen_ids",
|
|
741
|
+
"__refresh__",
|
|
742
|
+
"__reload__",
|
|
743
|
+
...options.paramsIgnore || []
|
|
744
|
+
];
|
|
745
|
+
return fn;
|
|
746
|
+
};
|
|
747
|
+
var generateFieldName2 = ({
|
|
748
|
+
func,
|
|
749
|
+
query
|
|
750
|
+
}) => {
|
|
751
|
+
let result = func.id;
|
|
752
|
+
if (!query) {
|
|
753
|
+
return result;
|
|
754
|
+
}
|
|
755
|
+
const queryObj = query;
|
|
756
|
+
const filteredKeys = Object.keys(queryObj).filter((key) => !func.paramsIgnore.includes(key)).sort();
|
|
757
|
+
const len = filteredKeys.length;
|
|
758
|
+
for (let i = 0; i < len; i++) {
|
|
759
|
+
const key = filteredKeys[i];
|
|
760
|
+
const value = queryObj[key];
|
|
761
|
+
let safeValue;
|
|
762
|
+
if (typeof value === "object" && value !== null) {
|
|
763
|
+
safeValue = stableSerialize(value);
|
|
764
|
+
} else {
|
|
765
|
+
safeValue = String(value);
|
|
840
766
|
}
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
767
|
+
const encoded = encodeURIComponent(safeValue);
|
|
768
|
+
result += `-${key}-${encoded}`;
|
|
769
|
+
}
|
|
770
|
+
return result;
|
|
771
|
+
};
|
|
844
772
|
|
|
845
773
|
exports.ENUM = enum_default;
|
|
846
774
|
exports.createApi = createApi;
|
|
775
|
+
exports.generateFieldName = generateFieldName2;
|
|
847
776
|
exports.initData = initData;
|
|
848
777
|
exports.initState = initState;
|
|
849
778
|
exports.loadMore = loadMore;
|