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