@flowlist/js-core 4.0.5-beta.0 → 4.0.6-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 +61 -50
- package/dist/index.d.ts +61 -50
- package/dist/index.global.js +160 -91
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +160 -91
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +160 -91
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -105,78 +105,89 @@ type FetchResultCallback<TParams, TResponse> = (obj: {
|
|
|
105
105
|
data: BaseApiResponse<TResponse>;
|
|
106
106
|
refresh: boolean;
|
|
107
107
|
}) => void;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
108
|
+
interface SetDataType {
|
|
109
|
+
readonly getter: FieldGetter;
|
|
110
|
+
readonly setter: FieldSetter;
|
|
111
|
+
readonly data: BaseApiResponse;
|
|
112
|
+
readonly fieldName: string;
|
|
113
|
+
readonly type: FetchType;
|
|
114
|
+
readonly page: number;
|
|
115
|
+
readonly insertBefore: boolean;
|
|
116
|
+
}
|
|
117
|
+
interface SetErrorType {
|
|
118
|
+
readonly setter: FieldSetter;
|
|
119
|
+
readonly fieldName: string;
|
|
120
|
+
readonly error: Error | null;
|
|
116
121
|
}
|
|
117
122
|
/**
|
|
118
|
-
*
|
|
123
|
+
* 初始化状态的外部参数
|
|
119
124
|
*/
|
|
120
|
-
interface
|
|
121
|
-
|
|
125
|
+
interface InitStateParams<P extends RequestParams = RequestParams, R = any> {
|
|
126
|
+
readonly func: ApiContract<P, R>;
|
|
127
|
+
readonly query?: P;
|
|
128
|
+
readonly opts?: Partial<DefaultField<R>>;
|
|
122
129
|
}
|
|
123
130
|
/**
|
|
124
|
-
*
|
|
131
|
+
* 初始化数据的外部参数
|
|
125
132
|
*/
|
|
126
|
-
interface
|
|
127
|
-
|
|
133
|
+
interface InitDataParams<P extends RequestParams = RequestParams, R = any> {
|
|
134
|
+
readonly func: ApiContract<P, R>;
|
|
135
|
+
readonly query?: P;
|
|
136
|
+
readonly callback?: FetchResultCallback<P, R>;
|
|
128
137
|
}
|
|
129
138
|
/**
|
|
130
|
-
*
|
|
139
|
+
* 加载更多的外部参数
|
|
131
140
|
*/
|
|
132
|
-
interface
|
|
133
|
-
|
|
134
|
-
|
|
141
|
+
interface LoadMoreParams<P extends RequestParams = RequestParams, R = any> {
|
|
142
|
+
readonly func: ApiContract<P, R>;
|
|
143
|
+
readonly query?: P;
|
|
144
|
+
readonly errorRetry?: boolean;
|
|
145
|
+
readonly callback?: FetchResultCallback<P, R>;
|
|
135
146
|
}
|
|
136
147
|
/**
|
|
137
|
-
*
|
|
138
|
-
* 这里的 TValue 尝试对更新的值进行约束
|
|
148
|
+
* 更新状态的外部参数
|
|
139
149
|
*/
|
|
140
|
-
interface
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
changeKey?: string;
|
|
150
|
+
interface UpdateStateParams<P extends RequestParams = RequestParams, R = any> {
|
|
151
|
+
readonly func: ApiContract<P, R>;
|
|
152
|
+
readonly query?: P;
|
|
153
|
+
readonly method: string;
|
|
154
|
+
readonly value: any;
|
|
155
|
+
readonly id?: ObjectKey | ObjectKey[];
|
|
156
|
+
readonly changeKey?: string;
|
|
157
|
+
readonly uniqueKey?: string;
|
|
149
158
|
}
|
|
150
|
-
interface
|
|
159
|
+
interface InitStateType<P extends RequestParams, R> extends InitStateParams<P, R> {
|
|
151
160
|
readonly getter: FieldGetter;
|
|
152
161
|
readonly setter: FieldSetter;
|
|
153
|
-
readonly data: BaseApiResponse;
|
|
154
|
-
readonly fieldName: string;
|
|
155
|
-
readonly type: FetchType;
|
|
156
|
-
readonly page: number;
|
|
157
|
-
readonly insertBefore: boolean;
|
|
158
162
|
}
|
|
159
|
-
interface
|
|
163
|
+
interface InitDataType<P extends RequestParams, R> extends InitDataParams<P, R> {
|
|
164
|
+
readonly getter: FieldGetter;
|
|
165
|
+
readonly setter: FieldSetter;
|
|
166
|
+
}
|
|
167
|
+
interface LoadMoreType<P extends RequestParams, R> extends LoadMoreParams<P, R> {
|
|
168
|
+
readonly getter: FieldGetter;
|
|
169
|
+
readonly setter: FieldSetter;
|
|
170
|
+
}
|
|
171
|
+
interface UpdateStateType<P extends RequestParams, R> extends UpdateStateParams<P, R> {
|
|
172
|
+
readonly getter: FieldGetter;
|
|
160
173
|
readonly setter: FieldSetter;
|
|
161
|
-
readonly fieldName: string;
|
|
162
|
-
readonly error: Error | null;
|
|
163
174
|
}
|
|
164
175
|
|
|
165
|
-
declare const initState: <P extends RequestParams, R>({ getter, setter, func, query, opts }: InitStateType<P, R>) => Promise<void>;
|
|
166
|
-
declare const initData: <P extends RequestParams, R>({ getter, setter, func, query, callback }: InitDataType<P, R>) => Promise<void>;
|
|
167
|
-
declare const loadMore: <P extends RequestParams, R>({ getter, setter, query, func, errorRetry, callback }: LoadMoreType<P, R>) => Promise<void>;
|
|
168
|
-
declare const updateState: <P extends RequestParams, R>({ getter, setter, func, query, method, id, value, changeKey }: UpdateStateType<P, R>) => Promise<unknown>;
|
|
169
|
-
declare const createApi: <TParams extends RequestParams, TResponse>(options: {
|
|
170
|
-
id: string;
|
|
171
|
-
type?: FetchType;
|
|
172
|
-
uniqueKey?: string;
|
|
173
|
-
paramsIgnore?: string[];
|
|
174
|
-
fetcher: (params: TParams) => Promise<BaseApiResponse<TResponse>>;
|
|
175
|
-
}) => ApiContract<TParams, TResponse>;
|
|
176
176
|
declare const generateFieldName$1: <P extends RequestParams, R>({ func, query }: {
|
|
177
177
|
func: ApiContract<P, R>;
|
|
178
178
|
query?: P;
|
|
179
179
|
}) => string;
|
|
180
|
+
declare const createApi: <P extends RequestParams, R>(options: {
|
|
181
|
+
id: string;
|
|
182
|
+
type?: FetchType;
|
|
183
|
+
uniqueKey?: string;
|
|
184
|
+
paramsIgnore?: string[];
|
|
185
|
+
fetcher: (params: P) => Promise<BaseApiResponse<R>>;
|
|
186
|
+
}) => ApiContract<P, R>;
|
|
187
|
+
declare const initState: <P extends RequestParams, R>({ getter, setter, func, query, opts }: InitStateType<P, R>) => Promise<void>;
|
|
188
|
+
declare const initData: <P extends RequestParams, R>({ getter, setter, func, query, callback }: InitDataType<P, R>) => Promise<void>;
|
|
189
|
+
declare const loadMore: <P extends RequestParams, R>({ getter, setter, query, func, errorRetry, callback }: LoadMoreType<P, R>) => Promise<void>;
|
|
190
|
+
declare const updateState: <P extends RequestParams, R>({ getter, setter, func, query, method, id, value, changeKey }: UpdateStateType<P, R>) => Promise<unknown>;
|
|
180
191
|
|
|
181
192
|
declare const isArray: (data: unknown) => data is any[];
|
|
182
193
|
/**
|
|
@@ -275,4 +286,4 @@ declare const _default: {
|
|
|
275
286
|
readonly DEFAULT_UNIQUE_KEY_NAME: "id";
|
|
276
287
|
};
|
|
277
288
|
|
|
278
|
-
export { type ApiContract, type BaseApiResponse, type DefaultField, _default as ENUM, type FetchResultCallback, type FetchType, type FieldGetter, type FieldKeys, type FieldSetter, type GenerateParamsResp, type GenerateParamsType, type InitDataType, type InitStateType, type KeyMap, type LoadMoreType, type ObjectKey, type RequestParams, type SetDataType, type SetErrorType, type SetterFuncParams, type UpdateStateType, createApi, generateFieldName$1 as generateFieldName, initData, initState, loadMore, updateState, utils };
|
|
289
|
+
export { type ApiContract, type BaseApiResponse, type DefaultField, _default as ENUM, type FetchResultCallback, type FetchType, type FieldGetter, type FieldKeys, type FieldSetter, type GenerateParamsResp, type GenerateParamsType, type InitDataParams, type InitDataType, type InitStateParams, type InitStateType, type KeyMap, type LoadMoreParams, type LoadMoreType, type ObjectKey, type RequestParams, type SetDataType, type SetErrorType, type SetterFuncParams, type UpdateStateParams, type UpdateStateType, createApi, generateFieldName$1 as generateFieldName, initData, initState, loadMore, updateState, utils };
|
package/dist/index.d.ts
CHANGED
|
@@ -105,78 +105,89 @@ type FetchResultCallback<TParams, TResponse> = (obj: {
|
|
|
105
105
|
data: BaseApiResponse<TResponse>;
|
|
106
106
|
refresh: boolean;
|
|
107
107
|
}) => void;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
108
|
+
interface SetDataType {
|
|
109
|
+
readonly getter: FieldGetter;
|
|
110
|
+
readonly setter: FieldSetter;
|
|
111
|
+
readonly data: BaseApiResponse;
|
|
112
|
+
readonly fieldName: string;
|
|
113
|
+
readonly type: FetchType;
|
|
114
|
+
readonly page: number;
|
|
115
|
+
readonly insertBefore: boolean;
|
|
116
|
+
}
|
|
117
|
+
interface SetErrorType {
|
|
118
|
+
readonly setter: FieldSetter;
|
|
119
|
+
readonly fieldName: string;
|
|
120
|
+
readonly error: Error | null;
|
|
116
121
|
}
|
|
117
122
|
/**
|
|
118
|
-
*
|
|
123
|
+
* 初始化状态的外部参数
|
|
119
124
|
*/
|
|
120
|
-
interface
|
|
121
|
-
|
|
125
|
+
interface InitStateParams<P extends RequestParams = RequestParams, R = any> {
|
|
126
|
+
readonly func: ApiContract<P, R>;
|
|
127
|
+
readonly query?: P;
|
|
128
|
+
readonly opts?: Partial<DefaultField<R>>;
|
|
122
129
|
}
|
|
123
130
|
/**
|
|
124
|
-
*
|
|
131
|
+
* 初始化数据的外部参数
|
|
125
132
|
*/
|
|
126
|
-
interface
|
|
127
|
-
|
|
133
|
+
interface InitDataParams<P extends RequestParams = RequestParams, R = any> {
|
|
134
|
+
readonly func: ApiContract<P, R>;
|
|
135
|
+
readonly query?: P;
|
|
136
|
+
readonly callback?: FetchResultCallback<P, R>;
|
|
128
137
|
}
|
|
129
138
|
/**
|
|
130
|
-
*
|
|
139
|
+
* 加载更多的外部参数
|
|
131
140
|
*/
|
|
132
|
-
interface
|
|
133
|
-
|
|
134
|
-
|
|
141
|
+
interface LoadMoreParams<P extends RequestParams = RequestParams, R = any> {
|
|
142
|
+
readonly func: ApiContract<P, R>;
|
|
143
|
+
readonly query?: P;
|
|
144
|
+
readonly errorRetry?: boolean;
|
|
145
|
+
readonly callback?: FetchResultCallback<P, R>;
|
|
135
146
|
}
|
|
136
147
|
/**
|
|
137
|
-
*
|
|
138
|
-
* 这里的 TValue 尝试对更新的值进行约束
|
|
148
|
+
* 更新状态的外部参数
|
|
139
149
|
*/
|
|
140
|
-
interface
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
changeKey?: string;
|
|
150
|
+
interface UpdateStateParams<P extends RequestParams = RequestParams, R = any> {
|
|
151
|
+
readonly func: ApiContract<P, R>;
|
|
152
|
+
readonly query?: P;
|
|
153
|
+
readonly method: string;
|
|
154
|
+
readonly value: any;
|
|
155
|
+
readonly id?: ObjectKey | ObjectKey[];
|
|
156
|
+
readonly changeKey?: string;
|
|
157
|
+
readonly uniqueKey?: string;
|
|
149
158
|
}
|
|
150
|
-
interface
|
|
159
|
+
interface InitStateType<P extends RequestParams, R> extends InitStateParams<P, R> {
|
|
151
160
|
readonly getter: FieldGetter;
|
|
152
161
|
readonly setter: FieldSetter;
|
|
153
|
-
readonly data: BaseApiResponse;
|
|
154
|
-
readonly fieldName: string;
|
|
155
|
-
readonly type: FetchType;
|
|
156
|
-
readonly page: number;
|
|
157
|
-
readonly insertBefore: boolean;
|
|
158
162
|
}
|
|
159
|
-
interface
|
|
163
|
+
interface InitDataType<P extends RequestParams, R> extends InitDataParams<P, R> {
|
|
164
|
+
readonly getter: FieldGetter;
|
|
165
|
+
readonly setter: FieldSetter;
|
|
166
|
+
}
|
|
167
|
+
interface LoadMoreType<P extends RequestParams, R> extends LoadMoreParams<P, R> {
|
|
168
|
+
readonly getter: FieldGetter;
|
|
169
|
+
readonly setter: FieldSetter;
|
|
170
|
+
}
|
|
171
|
+
interface UpdateStateType<P extends RequestParams, R> extends UpdateStateParams<P, R> {
|
|
172
|
+
readonly getter: FieldGetter;
|
|
160
173
|
readonly setter: FieldSetter;
|
|
161
|
-
readonly fieldName: string;
|
|
162
|
-
readonly error: Error | null;
|
|
163
174
|
}
|
|
164
175
|
|
|
165
|
-
declare const initState: <P extends RequestParams, R>({ getter, setter, func, query, opts }: InitStateType<P, R>) => Promise<void>;
|
|
166
|
-
declare const initData: <P extends RequestParams, R>({ getter, setter, func, query, callback }: InitDataType<P, R>) => Promise<void>;
|
|
167
|
-
declare const loadMore: <P extends RequestParams, R>({ getter, setter, query, func, errorRetry, callback }: LoadMoreType<P, R>) => Promise<void>;
|
|
168
|
-
declare const updateState: <P extends RequestParams, R>({ getter, setter, func, query, method, id, value, changeKey }: UpdateStateType<P, R>) => Promise<unknown>;
|
|
169
|
-
declare const createApi: <TParams extends RequestParams, TResponse>(options: {
|
|
170
|
-
id: string;
|
|
171
|
-
type?: FetchType;
|
|
172
|
-
uniqueKey?: string;
|
|
173
|
-
paramsIgnore?: string[];
|
|
174
|
-
fetcher: (params: TParams) => Promise<BaseApiResponse<TResponse>>;
|
|
175
|
-
}) => ApiContract<TParams, TResponse>;
|
|
176
176
|
declare const generateFieldName$1: <P extends RequestParams, R>({ func, query }: {
|
|
177
177
|
func: ApiContract<P, R>;
|
|
178
178
|
query?: P;
|
|
179
179
|
}) => string;
|
|
180
|
+
declare const createApi: <P extends RequestParams, R>(options: {
|
|
181
|
+
id: string;
|
|
182
|
+
type?: FetchType;
|
|
183
|
+
uniqueKey?: string;
|
|
184
|
+
paramsIgnore?: string[];
|
|
185
|
+
fetcher: (params: P) => Promise<BaseApiResponse<R>>;
|
|
186
|
+
}) => ApiContract<P, R>;
|
|
187
|
+
declare const initState: <P extends RequestParams, R>({ getter, setter, func, query, opts }: InitStateType<P, R>) => Promise<void>;
|
|
188
|
+
declare const initData: <P extends RequestParams, R>({ getter, setter, func, query, callback }: InitDataType<P, R>) => Promise<void>;
|
|
189
|
+
declare const loadMore: <P extends RequestParams, R>({ getter, setter, query, func, errorRetry, callback }: LoadMoreType<P, R>) => Promise<void>;
|
|
190
|
+
declare const updateState: <P extends RequestParams, R>({ getter, setter, func, query, method, id, value, changeKey }: UpdateStateType<P, R>) => Promise<unknown>;
|
|
180
191
|
|
|
181
192
|
declare const isArray: (data: unknown) => data is any[];
|
|
182
193
|
/**
|
|
@@ -275,4 +286,4 @@ declare const _default: {
|
|
|
275
286
|
readonly DEFAULT_UNIQUE_KEY_NAME: "id";
|
|
276
287
|
};
|
|
277
288
|
|
|
278
|
-
export { type ApiContract, type BaseApiResponse, type DefaultField, _default as ENUM, type FetchResultCallback, type FetchType, type FieldGetter, type FieldKeys, type FieldSetter, type GenerateParamsResp, type GenerateParamsType, type InitDataType, type InitStateType, type KeyMap, type LoadMoreType, type ObjectKey, type RequestParams, type SetDataType, type SetErrorType, type SetterFuncParams, type UpdateStateType, createApi, generateFieldName$1 as generateFieldName, initData, initState, loadMore, updateState, utils };
|
|
289
|
+
export { type ApiContract, type BaseApiResponse, type DefaultField, _default as ENUM, type FetchResultCallback, type FetchType, type FieldGetter, type FieldKeys, type FieldSetter, type GenerateParamsResp, type GenerateParamsType, type InitDataParams, type InitDataType, type InitStateParams, type InitStateType, type KeyMap, type LoadMoreParams, type LoadMoreType, type ObjectKey, type RequestParams, type SetDataType, type SetErrorType, type SetterFuncParams, type UpdateStateParams, type UpdateStateType, createApi, generateFieldName$1 as generateFieldName, initData, initState, loadMore, updateState, utils };
|
package/dist/index.global.js
CHANGED
|
@@ -506,6 +506,39 @@ var FlowList = (function (exports) {
|
|
|
506
506
|
};
|
|
507
507
|
|
|
508
508
|
// src/actions.ts
|
|
509
|
+
var generateFieldName2 = ({
|
|
510
|
+
func,
|
|
511
|
+
query
|
|
512
|
+
}) => {
|
|
513
|
+
let result = func.id;
|
|
514
|
+
if (!query) return result;
|
|
515
|
+
const queryObj = query;
|
|
516
|
+
const filteredKeys = Object.keys(queryObj).filter((key) => !func.paramsIgnore.includes(key)).sort();
|
|
517
|
+
for (const key of filteredKeys) {
|
|
518
|
+
const value = queryObj[key];
|
|
519
|
+
const safeValue = typeof value === "object" && value !== null ? stableSerialize(value) : String(value);
|
|
520
|
+
result += `-${key}-${encodeURIComponent(safeValue)}`;
|
|
521
|
+
}
|
|
522
|
+
return result;
|
|
523
|
+
};
|
|
524
|
+
var createApi = (options) => {
|
|
525
|
+
const fn = ((params) => options.fetcher(params));
|
|
526
|
+
const metadata = {
|
|
527
|
+
id: options.id,
|
|
528
|
+
type: options.type || enum_default.FETCH_TYPE.SCROLL_LOAD_MORE,
|
|
529
|
+
uniqueKey: options.uniqueKey || enum_default.DEFAULT_UNIQUE_KEY_NAME,
|
|
530
|
+
paramsIgnore: [
|
|
531
|
+
"page",
|
|
532
|
+
"is_up",
|
|
533
|
+
"since_id",
|
|
534
|
+
"seen_ids",
|
|
535
|
+
"__refresh__",
|
|
536
|
+
"__reload__",
|
|
537
|
+
...options.paramsIgnore || []
|
|
538
|
+
]
|
|
539
|
+
};
|
|
540
|
+
return Object.freeze(Object.assign(fn, metadata));
|
|
541
|
+
};
|
|
509
542
|
var initState = ({
|
|
510
543
|
getter,
|
|
511
544
|
setter,
|
|
@@ -515,18 +548,12 @@ var FlowList = (function (exports) {
|
|
|
515
548
|
}) => {
|
|
516
549
|
return new Promise((resolve) => {
|
|
517
550
|
const fieldName = generateFieldName2({ func, query });
|
|
518
|
-
|
|
519
|
-
if (fieldData) {
|
|
520
|
-
resolve();
|
|
521
|
-
return;
|
|
522
|
-
}
|
|
551
|
+
if (getter(fieldName)) return resolve();
|
|
523
552
|
setter({
|
|
524
553
|
key: fieldName,
|
|
525
554
|
type: enum_default.SETTER_TYPE.RESET,
|
|
526
555
|
value: generateDefaultField(opts),
|
|
527
|
-
callback: () =>
|
|
528
|
-
resolve();
|
|
529
|
-
}
|
|
556
|
+
callback: () => resolve()
|
|
530
557
|
});
|
|
531
558
|
});
|
|
532
559
|
};
|
|
@@ -546,14 +573,10 @@ var FlowList = (function (exports) {
|
|
|
546
573
|
if (fieldData && fieldData.loading) return resolve();
|
|
547
574
|
if (fieldData && fieldData.fetched && !doRefresh) return resolve();
|
|
548
575
|
const params = generateRequestParams({
|
|
549
|
-
field: generateDefaultField({
|
|
550
|
-
...fieldData,
|
|
551
|
-
fetched: false
|
|
552
|
-
}),
|
|
576
|
+
field: generateDefaultField({ ...fieldData, fetched: false }),
|
|
553
577
|
uniqueKey: func.uniqueKey,
|
|
554
578
|
type: func.type,
|
|
555
579
|
query
|
|
556
|
-
// 内部生成逻辑兼容
|
|
557
580
|
});
|
|
558
581
|
const executeFetch = () => {
|
|
559
582
|
func(params).then((data) => {
|
|
@@ -567,11 +590,7 @@ var FlowList = (function (exports) {
|
|
|
567
590
|
page: params.page || 0,
|
|
568
591
|
insertBefore: false
|
|
569
592
|
}).then(() => {
|
|
570
|
-
callback?.({
|
|
571
|
-
params,
|
|
572
|
-
data,
|
|
573
|
-
refresh: doRefresh
|
|
574
|
-
});
|
|
593
|
+
callback?.({ params, data, refresh: doRefresh });
|
|
575
594
|
resolve();
|
|
576
595
|
});
|
|
577
596
|
};
|
|
@@ -596,11 +615,7 @@ var FlowList = (function (exports) {
|
|
|
596
615
|
setter({
|
|
597
616
|
key: fieldName,
|
|
598
617
|
type: enum_default.SETTER_TYPE.RESET,
|
|
599
|
-
value: {
|
|
600
|
-
...generateDefaultField(),
|
|
601
|
-
loading: true,
|
|
602
|
-
error: null
|
|
603
|
-
},
|
|
618
|
+
value: { ...generateDefaultField(), loading: true, error: null },
|
|
604
619
|
callback: executeFetch
|
|
605
620
|
});
|
|
606
621
|
}
|
|
@@ -615,36 +630,20 @@ var FlowList = (function (exports) {
|
|
|
615
630
|
}) => new Promise((resolve, reject) => {
|
|
616
631
|
const fieldName = generateFieldName2({ func, query });
|
|
617
632
|
const fieldData = getter(fieldName);
|
|
618
|
-
const type = func.type;
|
|
619
633
|
if (!fieldData || fieldData.loading || fieldData.nothing) return resolve();
|
|
620
634
|
if (fieldData.noMore && !errorRetry) return resolve();
|
|
621
|
-
|
|
622
|
-
|
|
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
|
-
};
|
|
635
|
+
const type = func.type;
|
|
636
|
+
if (type === enum_default.FETCH_TYPE.PAGINATION && query?.page != null && Number(query.page) === fieldData.page) {
|
|
637
|
+
return resolve();
|
|
638
638
|
}
|
|
639
|
+
const loadingState = type === enum_default.FETCH_TYPE.PAGINATION ? { loading: true, error: null, result: [], extra: null } : { loading: true, error: null };
|
|
639
640
|
const params = generateRequestParams({
|
|
640
641
|
field: fieldData,
|
|
641
642
|
uniqueKey: func.uniqueKey,
|
|
642
643
|
type,
|
|
643
644
|
query
|
|
644
645
|
});
|
|
645
|
-
if (fieldData.extra)
|
|
646
|
-
params[enum_default.FIELD_DATA.EXTRA_KEY] = fieldData.extra;
|
|
647
|
-
}
|
|
646
|
+
if (fieldData.extra) params.extra = fieldData.extra;
|
|
648
647
|
setter({
|
|
649
648
|
key: fieldName,
|
|
650
649
|
type: enum_default.SETTER_TYPE.MERGE,
|
|
@@ -660,11 +659,7 @@ var FlowList = (function (exports) {
|
|
|
660
659
|
page: params.page || 0,
|
|
661
660
|
insertBefore: !!query?.is_up
|
|
662
661
|
}).then(() => {
|
|
663
|
-
callback?.({
|
|
664
|
-
params,
|
|
665
|
-
data,
|
|
666
|
-
refresh: false
|
|
667
|
-
});
|
|
662
|
+
callback?.({ params, data, refresh: false });
|
|
668
663
|
resolve();
|
|
669
664
|
});
|
|
670
665
|
}).catch((error) => {
|
|
@@ -697,7 +692,7 @@ var FlowList = (function (exports) {
|
|
|
697
692
|
}
|
|
698
693
|
const _id = id;
|
|
699
694
|
const _uniqueKey = func.uniqueKey || enum_default.DEFAULT_UNIQUE_KEY_NAME;
|
|
700
|
-
changeKey || enum_default.FIELD_DATA.RESULT_KEY;
|
|
695
|
+
const _changeKey = changeKey || enum_default.FIELD_DATA.RESULT_KEY;
|
|
701
696
|
const beforeLength = computeResultLength(
|
|
702
697
|
fieldData[enum_default.FIELD_DATA.RESULT_KEY]
|
|
703
698
|
);
|
|
@@ -712,6 +707,121 @@ var FlowList = (function (exports) {
|
|
|
712
707
|
const searchResult = resultArray ? searchValueByKey(resultArray, objectKeyId, _uniqueKey) : void 0;
|
|
713
708
|
resolve(searchResult);
|
|
714
709
|
return;
|
|
710
|
+
} else if (method === enum_default.CHANGE_TYPE.RESULT_UPDATE_KV) {
|
|
711
|
+
const objectKeyId = toObjectKey(_id);
|
|
712
|
+
if (objectKeyId === void 0) {
|
|
713
|
+
reject(new Error("ID is required for RESULT_UPDATE_KV."));
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
if (resultArray) {
|
|
717
|
+
const matchedIndex = computeMatchedItemIndex(
|
|
718
|
+
objectKeyId,
|
|
719
|
+
resultArray,
|
|
720
|
+
_uniqueKey
|
|
721
|
+
);
|
|
722
|
+
if (matchedIndex >= 0 && isKeyMap(resultArray[matchedIndex])) {
|
|
723
|
+
updateObjectDeepValue(resultArray[matchedIndex], _changeKey, value);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
resolve(null);
|
|
727
|
+
} else if (method === enum_default.CHANGE_TYPE.RESULT_ITEM_MERGE) {
|
|
728
|
+
const objectKeyId = toObjectKey(_id);
|
|
729
|
+
if (objectKeyId === void 0) {
|
|
730
|
+
reject(new Error("ID is required for RESULT_ITEM_MERGE."));
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
if (resultArray && isKeyMap(value)) {
|
|
734
|
+
const matchedIndex = computeMatchedItemIndex(
|
|
735
|
+
objectKeyId,
|
|
736
|
+
resultArray,
|
|
737
|
+
_uniqueKey
|
|
738
|
+
);
|
|
739
|
+
updateArrayItem(resultArray, matchedIndex, (item) => ({
|
|
740
|
+
...item,
|
|
741
|
+
...value
|
|
742
|
+
}));
|
|
743
|
+
}
|
|
744
|
+
resolve(null);
|
|
745
|
+
} else if (method === enum_default.CHANGE_TYPE.RESET_FIELD) {
|
|
746
|
+
if (_changeKey === enum_default.FIELD_DATA.RESULT_KEY && isKeyMapArray(value)) {
|
|
747
|
+
newFieldData.result = value;
|
|
748
|
+
} else if (_changeKey === enum_default.FIELD_DATA.EXTRA_KEY && isKeyMap(value)) {
|
|
749
|
+
newFieldData.extra = value;
|
|
750
|
+
}
|
|
751
|
+
resolve(null);
|
|
752
|
+
} else {
|
|
753
|
+
let modifyValue;
|
|
754
|
+
if (_changeKey === enum_default.FIELD_DATA.RESULT_KEY) {
|
|
755
|
+
modifyValue = newFieldData.result;
|
|
756
|
+
} else if (_changeKey === enum_default.FIELD_DATA.EXTRA_KEY) {
|
|
757
|
+
modifyValue = newFieldData.extra;
|
|
758
|
+
} else {
|
|
759
|
+
modifyValue = getObjectDeepValue(newFieldData, _changeKey);
|
|
760
|
+
}
|
|
761
|
+
if (modifyValue == null) {
|
|
762
|
+
modifyValue = [];
|
|
763
|
+
}
|
|
764
|
+
const objectKeyId = toObjectKey(_id);
|
|
765
|
+
const matchedIndex = objectKeyId !== void 0 && isKeyMapArray(modifyValue) ? computeMatchedItemIndex(objectKeyId, modifyValue, _uniqueKey) : -1;
|
|
766
|
+
switch (method) {
|
|
767
|
+
case enum_default.CHANGE_TYPE.RESULT_ADD_AFTER:
|
|
768
|
+
if (isArray(modifyValue)) {
|
|
769
|
+
modifyValue = isArray(value) ? [...modifyValue, ...value] : [...modifyValue, value];
|
|
770
|
+
}
|
|
771
|
+
break;
|
|
772
|
+
case enum_default.CHANGE_TYPE.RESULT_ADD_BEFORE:
|
|
773
|
+
if (isArray(modifyValue)) {
|
|
774
|
+
modifyValue = isArray(value) ? [...value, ...modifyValue] : [value, ...modifyValue];
|
|
775
|
+
}
|
|
776
|
+
break;
|
|
777
|
+
case enum_default.CHANGE_TYPE.RESULT_REMOVE_BY_ID:
|
|
778
|
+
if (isKeyMapArray(modifyValue)) {
|
|
779
|
+
if (matchedIndex >= 0) {
|
|
780
|
+
modifyValue.splice(matchedIndex, 1);
|
|
781
|
+
} else if (isObjectKeyArray(_id)) {
|
|
782
|
+
const idSet = new Set(_id);
|
|
783
|
+
modifyValue = modifyValue.filter((item) => {
|
|
784
|
+
const itemKey = getObjectDeepValue(item, _uniqueKey);
|
|
785
|
+
return !isObjectKey(itemKey) || !idSet.has(itemKey);
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
break;
|
|
790
|
+
case enum_default.CHANGE_TYPE.RESULT_INSERT_TO_BEFORE:
|
|
791
|
+
if (isArray(modifyValue) && matchedIndex >= 0) {
|
|
792
|
+
modifyValue.splice(matchedIndex, 0, value);
|
|
793
|
+
}
|
|
794
|
+
break;
|
|
795
|
+
case enum_default.CHANGE_TYPE.RESULT_INSERT_TO_AFTER:
|
|
796
|
+
if (isArray(modifyValue) && matchedIndex >= 0) {
|
|
797
|
+
modifyValue.splice(matchedIndex + 1, 0, value);
|
|
798
|
+
}
|
|
799
|
+
break;
|
|
800
|
+
case enum_default.CHANGE_TYPE.RESULT_LIST_MERGE:
|
|
801
|
+
if (isKeyMapArray(modifyValue)) {
|
|
802
|
+
if (isKeyMapArray(value)) {
|
|
803
|
+
combineArrayData(modifyValue, value, _uniqueKey);
|
|
804
|
+
} else if (isKeyMap(value)) {
|
|
805
|
+
const valueAsRecord = {};
|
|
806
|
+
for (const [k, v] of Object.entries(value)) {
|
|
807
|
+
if (isKeyMap(v)) {
|
|
808
|
+
valueAsRecord[k] = v;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
combineArrayData(modifyValue, valueAsRecord, _uniqueKey);
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
break;
|
|
815
|
+
default:
|
|
816
|
+
resolve(null);
|
|
817
|
+
return;
|
|
818
|
+
}
|
|
819
|
+
if (_changeKey === enum_default.FIELD_DATA.RESULT_KEY && isKeyMapArray(modifyValue)) {
|
|
820
|
+
newFieldData.result = modifyValue;
|
|
821
|
+
} else if (_changeKey === enum_default.FIELD_DATA.EXTRA_KEY && isKeyMap(modifyValue)) {
|
|
822
|
+
newFieldData.extra = modifyValue;
|
|
823
|
+
}
|
|
824
|
+
resolve(null);
|
|
715
825
|
}
|
|
716
826
|
const afterLength = computeResultLength(
|
|
717
827
|
newFieldData[enum_default.FIELD_DATA.RESULT_KEY]
|
|
@@ -728,47 +838,6 @@ var FlowList = (function (exports) {
|
|
|
728
838
|
});
|
|
729
839
|
});
|
|
730
840
|
};
|
|
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);
|
|
766
|
-
}
|
|
767
|
-
const encoded = encodeURIComponent(safeValue);
|
|
768
|
-
result += `-${key}-${encoded}`;
|
|
769
|
-
}
|
|
770
|
-
return result;
|
|
771
|
-
};
|
|
772
841
|
|
|
773
842
|
exports.ENUM = enum_default;
|
|
774
843
|
exports.createApi = createApi;
|