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