@flowlist/js-core 4.0.6-beta.0 → 4.0.8-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 CHANGED
@@ -39,7 +39,6 @@ interface RequestParams {
39
39
  [key: string]: any;
40
40
  __refresh__?: boolean;
41
41
  __reload__?: boolean;
42
- is_up?: 0 | 1 | boolean;
43
42
  page?: number;
44
43
  sinceId?: ObjectKey;
45
44
  }
@@ -58,6 +57,7 @@ interface ApiContract<TParams extends RequestParams, TResponse> {
58
57
  */
59
58
  readonly id: string;
60
59
  readonly type: FetchType;
60
+ readonly is_up: boolean;
61
61
  readonly uniqueKey: string;
62
62
  readonly paramsIgnore: string[];
63
63
  }
@@ -94,6 +94,7 @@ interface GenerateParamsResp extends RequestParams {
94
94
  interface GenerateParamsType {
95
95
  readonly field: DefaultField;
96
96
  readonly uniqueKey?: string;
97
+ readonly is_up?: boolean;
97
98
  readonly query?: KeyMap;
98
99
  readonly type: FetchType;
99
100
  }
@@ -181,6 +182,7 @@ declare const createApi: <P extends RequestParams, R>(options: {
181
182
  id: string;
182
183
  type?: FetchType;
183
184
  uniqueKey?: string;
185
+ is_up?: boolean;
184
186
  paramsIgnore?: string[];
185
187
  fetcher: (params: P) => Promise<BaseApiResponse<R>>;
186
188
  }) => ApiContract<P, R>;
@@ -189,6 +191,38 @@ declare const initData: <P extends RequestParams, R>({ getter, setter, func, que
189
191
  declare const loadMore: <P extends RequestParams, R>({ getter, setter, query, func, errorRetry, callback }: LoadMoreType<P, R>) => Promise<void>;
190
192
  declare const updateState: <P extends RequestParams, R>({ getter, setter, func, query, method, id, value, changeKey }: UpdateStateType<P, R>) => Promise<unknown>;
191
193
 
194
+ declare const _default: {
195
+ readonly SETTER_TYPE: {
196
+ readonly RESET: 0;
197
+ readonly MERGE: 1;
198
+ };
199
+ readonly FETCH_TYPE_ARRAY: readonly ["jump", "sinceId", "page", "seenIds", "auto"];
200
+ readonly FETCH_TYPE: {
201
+ readonly PAGINATION: "jump";
202
+ readonly SINCE_FIRST_OR_END_ID: "sinceId";
203
+ readonly SCROLL_LOAD_MORE: "page";
204
+ readonly HAS_LOADED_IDS: "seenIds";
205
+ readonly AUTO: "auto";
206
+ };
207
+ readonly CHANGE_TYPE: {
208
+ readonly SEARCH_FIELD: "search";
209
+ readonly RESET_FIELD: "reset";
210
+ readonly RESULT_UPDATE_KV: "update";
211
+ readonly RESULT_ADD_AFTER: "push";
212
+ readonly RESULT_ADD_BEFORE: "unshift";
213
+ readonly RESULT_REMOVE_BY_ID: "delete";
214
+ readonly RESULT_INSERT_TO_BEFORE: "insert-before";
215
+ readonly RESULT_INSERT_TO_AFTER: "insert-after";
216
+ readonly RESULT_LIST_MERGE: "patch";
217
+ readonly RESULT_ITEM_MERGE: "merge";
218
+ };
219
+ readonly FIELD_DATA: {
220
+ readonly RESULT_KEY: "result";
221
+ readonly EXTRA_KEY: "extra";
222
+ };
223
+ readonly DEFAULT_UNIQUE_KEY_NAME: "id";
224
+ };
225
+
192
226
  declare const isArray: (data: unknown) => data is any[];
193
227
  /**
194
228
  * 检查是否为对象结果
@@ -204,10 +238,12 @@ declare const isObjectKey: (value: unknown) => value is ObjectKey;
204
238
  declare const isKeyMap: (value: unknown) => value is KeyMap;
205
239
  /**
206
240
  * 检查是否为 KeyMap 数组
241
+ * 性能优化:使用 for 循环替代 every,提前退出
207
242
  */
208
243
  declare const isKeyMapArray: (value: unknown) => value is KeyMap[];
209
244
  /**
210
245
  * 检查是否为 ObjectKey 数组
246
+ * 性能优化:使用 for 循环替代 every,提前退出
211
247
  */
212
248
  declare const isObjectKeyArray: (value: unknown) => value is ObjectKey[];
213
249
  declare const stableSerialize: (value: unknown) => string;
@@ -220,11 +256,32 @@ declare const generateFieldName: <P extends RequestParams, R>({ func, query }: {
220
256
  declare const getObjectDeepValue: (field: unknown, keys: string | string[]) => unknown;
221
257
  declare const updateObjectDeepValue: (field: KeyMap, changeKey: string, value: unknown) => void;
222
258
  declare const searchValueByKey: (result: any[] | Record<string, any>, id: ObjectKey, key: string) => unknown;
259
+ /**
260
+ * 查找匹配项的索引
261
+ * 性能优化:
262
+ * 1. 提前字符串化避免重复转换
263
+ * 2. 优化简单 key 的访问路径(无需 split)
264
+ * 3. 减少函数调用开销
265
+ */
223
266
  declare const computeMatchedItemIndex: (itemId: ObjectKey, fieldArr: any[], changingKey: string) => number;
267
+ /**
268
+ * 合并数组数据
269
+ * 性能优化:
270
+ * 1. 使用 Map 进行 O(1) 查找
271
+ * 2. 创建新对象确保响应式
272
+ * 3. 缓存 changingKey 的解析结果
273
+ */
224
274
  declare const combineArrayData: (fieldArray: any[], value: any[] | Record<ObjectKey, KeyMap>, changingKey: string) => void;
275
+ /**
276
+ * 设置响应式字段
277
+ * 性能优化:
278
+ * 1. 快速路径优化常见场景
279
+ * 2. 减少条件判断
280
+ * 3. 使用原生方法 concat 而非展开运算符(在大数组时性能更好)
281
+ */
225
282
  declare const setReactivityField: (field: DefaultField, key: FieldKeys, value: unknown, type: FetchType, insertBefore: boolean) => void;
226
283
  declare const computeResultLength: (data: unknown) => number;
227
- declare const generateRequestParams: ({ field, uniqueKey, query, type }: GenerateParamsType) => GenerateParamsResp;
284
+ declare const generateRequestParams: ({ field, uniqueKey, query, is_up, type }: GenerateParamsType) => GenerateParamsResp;
228
285
  declare const toObjectKey: (id: ObjectKey | ObjectKey[] | undefined) => ObjectKey | undefined;
229
286
  declare const getResultAsArray: (field: DefaultField) => any[] | null;
230
287
  declare const updateArrayItem: (arr: any[], index: number, updater: (item: KeyMap) => KeyMap) => void;
@@ -254,36 +311,4 @@ declare namespace utils {
254
311
  export { utils_combineArrayData as combineArrayData, utils_computeMatchedItemIndex as computeMatchedItemIndex, utils_computeResultLength as computeResultLength, utils_generateDefaultField as generateDefaultField, utils_generateFieldName as generateFieldName, utils_generateRequestParams as generateRequestParams, utils_getObjectDeepValue as getObjectDeepValue, utils_getResultAsArray as getResultAsArray, utils_isArray as isArray, utils_isKeyMap as isKeyMap, utils_isKeyMapArray as isKeyMapArray, utils_isObjectKey as isObjectKey, utils_isObjectKeyArray as isObjectKeyArray, utils_isObjectResult as isObjectResult, utils_isResultObject as isResultObject, utils_searchValueByKey as searchValueByKey, utils_setReactivityField as setReactivityField, utils_stableSerialize as stableSerialize, utils_toObjectKey as toObjectKey, utils_updateArrayItem as updateArrayItem, utils_updateObjectDeepValue as updateObjectDeepValue };
255
312
  }
256
313
 
257
- declare const _default: {
258
- readonly SETTER_TYPE: {
259
- readonly RESET: 0;
260
- readonly MERGE: 1;
261
- };
262
- readonly FETCH_TYPE_ARRAY: readonly ["jump", "sinceId", "page", "seenIds", "auto"];
263
- readonly FETCH_TYPE: {
264
- readonly PAGINATION: "jump";
265
- readonly SINCE_FIRST_OR_END_ID: "sinceId";
266
- readonly SCROLL_LOAD_MORE: "page";
267
- readonly HAS_LOADED_IDS: "seenIds";
268
- readonly AUTO: "auto";
269
- };
270
- readonly CHANGE_TYPE: {
271
- readonly SEARCH_FIELD: "search";
272
- readonly RESET_FIELD: "reset";
273
- readonly RESULT_UPDATE_KV: "update";
274
- readonly RESULT_ADD_AFTER: "push";
275
- readonly RESULT_ADD_BEFORE: "unshift";
276
- readonly RESULT_REMOVE_BY_ID: "delete";
277
- readonly RESULT_INSERT_TO_BEFORE: "insert-before";
278
- readonly RESULT_INSERT_TO_AFTER: "insert-after";
279
- readonly RESULT_LIST_MERGE: "patch";
280
- readonly RESULT_ITEM_MERGE: "merge";
281
- };
282
- readonly FIELD_DATA: {
283
- readonly RESULT_KEY: "result";
284
- readonly EXTRA_KEY: "extra";
285
- };
286
- readonly DEFAULT_UNIQUE_KEY_NAME: "id";
287
- };
288
-
289
314
  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
@@ -39,7 +39,6 @@ interface RequestParams {
39
39
  [key: string]: any;
40
40
  __refresh__?: boolean;
41
41
  __reload__?: boolean;
42
- is_up?: 0 | 1 | boolean;
43
42
  page?: number;
44
43
  sinceId?: ObjectKey;
45
44
  }
@@ -58,6 +57,7 @@ interface ApiContract<TParams extends RequestParams, TResponse> {
58
57
  */
59
58
  readonly id: string;
60
59
  readonly type: FetchType;
60
+ readonly is_up: boolean;
61
61
  readonly uniqueKey: string;
62
62
  readonly paramsIgnore: string[];
63
63
  }
@@ -94,6 +94,7 @@ interface GenerateParamsResp extends RequestParams {
94
94
  interface GenerateParamsType {
95
95
  readonly field: DefaultField;
96
96
  readonly uniqueKey?: string;
97
+ readonly is_up?: boolean;
97
98
  readonly query?: KeyMap;
98
99
  readonly type: FetchType;
99
100
  }
@@ -181,6 +182,7 @@ declare const createApi: <P extends RequestParams, R>(options: {
181
182
  id: string;
182
183
  type?: FetchType;
183
184
  uniqueKey?: string;
185
+ is_up?: boolean;
184
186
  paramsIgnore?: string[];
185
187
  fetcher: (params: P) => Promise<BaseApiResponse<R>>;
186
188
  }) => ApiContract<P, R>;
@@ -189,6 +191,38 @@ declare const initData: <P extends RequestParams, R>({ getter, setter, func, que
189
191
  declare const loadMore: <P extends RequestParams, R>({ getter, setter, query, func, errorRetry, callback }: LoadMoreType<P, R>) => Promise<void>;
190
192
  declare const updateState: <P extends RequestParams, R>({ getter, setter, func, query, method, id, value, changeKey }: UpdateStateType<P, R>) => Promise<unknown>;
191
193
 
194
+ declare const _default: {
195
+ readonly SETTER_TYPE: {
196
+ readonly RESET: 0;
197
+ readonly MERGE: 1;
198
+ };
199
+ readonly FETCH_TYPE_ARRAY: readonly ["jump", "sinceId", "page", "seenIds", "auto"];
200
+ readonly FETCH_TYPE: {
201
+ readonly PAGINATION: "jump";
202
+ readonly SINCE_FIRST_OR_END_ID: "sinceId";
203
+ readonly SCROLL_LOAD_MORE: "page";
204
+ readonly HAS_LOADED_IDS: "seenIds";
205
+ readonly AUTO: "auto";
206
+ };
207
+ readonly CHANGE_TYPE: {
208
+ readonly SEARCH_FIELD: "search";
209
+ readonly RESET_FIELD: "reset";
210
+ readonly RESULT_UPDATE_KV: "update";
211
+ readonly RESULT_ADD_AFTER: "push";
212
+ readonly RESULT_ADD_BEFORE: "unshift";
213
+ readonly RESULT_REMOVE_BY_ID: "delete";
214
+ readonly RESULT_INSERT_TO_BEFORE: "insert-before";
215
+ readonly RESULT_INSERT_TO_AFTER: "insert-after";
216
+ readonly RESULT_LIST_MERGE: "patch";
217
+ readonly RESULT_ITEM_MERGE: "merge";
218
+ };
219
+ readonly FIELD_DATA: {
220
+ readonly RESULT_KEY: "result";
221
+ readonly EXTRA_KEY: "extra";
222
+ };
223
+ readonly DEFAULT_UNIQUE_KEY_NAME: "id";
224
+ };
225
+
192
226
  declare const isArray: (data: unknown) => data is any[];
193
227
  /**
194
228
  * 检查是否为对象结果
@@ -204,10 +238,12 @@ declare const isObjectKey: (value: unknown) => value is ObjectKey;
204
238
  declare const isKeyMap: (value: unknown) => value is KeyMap;
205
239
  /**
206
240
  * 检查是否为 KeyMap 数组
241
+ * 性能优化:使用 for 循环替代 every,提前退出
207
242
  */
208
243
  declare const isKeyMapArray: (value: unknown) => value is KeyMap[];
209
244
  /**
210
245
  * 检查是否为 ObjectKey 数组
246
+ * 性能优化:使用 for 循环替代 every,提前退出
211
247
  */
212
248
  declare const isObjectKeyArray: (value: unknown) => value is ObjectKey[];
213
249
  declare const stableSerialize: (value: unknown) => string;
@@ -220,11 +256,32 @@ declare const generateFieldName: <P extends RequestParams, R>({ func, query }: {
220
256
  declare const getObjectDeepValue: (field: unknown, keys: string | string[]) => unknown;
221
257
  declare const updateObjectDeepValue: (field: KeyMap, changeKey: string, value: unknown) => void;
222
258
  declare const searchValueByKey: (result: any[] | Record<string, any>, id: ObjectKey, key: string) => unknown;
259
+ /**
260
+ * 查找匹配项的索引
261
+ * 性能优化:
262
+ * 1. 提前字符串化避免重复转换
263
+ * 2. 优化简单 key 的访问路径(无需 split)
264
+ * 3. 减少函数调用开销
265
+ */
223
266
  declare const computeMatchedItemIndex: (itemId: ObjectKey, fieldArr: any[], changingKey: string) => number;
267
+ /**
268
+ * 合并数组数据
269
+ * 性能优化:
270
+ * 1. 使用 Map 进行 O(1) 查找
271
+ * 2. 创建新对象确保响应式
272
+ * 3. 缓存 changingKey 的解析结果
273
+ */
224
274
  declare const combineArrayData: (fieldArray: any[], value: any[] | Record<ObjectKey, KeyMap>, changingKey: string) => void;
275
+ /**
276
+ * 设置响应式字段
277
+ * 性能优化:
278
+ * 1. 快速路径优化常见场景
279
+ * 2. 减少条件判断
280
+ * 3. 使用原生方法 concat 而非展开运算符(在大数组时性能更好)
281
+ */
225
282
  declare const setReactivityField: (field: DefaultField, key: FieldKeys, value: unknown, type: FetchType, insertBefore: boolean) => void;
226
283
  declare const computeResultLength: (data: unknown) => number;
227
- declare const generateRequestParams: ({ field, uniqueKey, query, type }: GenerateParamsType) => GenerateParamsResp;
284
+ declare const generateRequestParams: ({ field, uniqueKey, query, is_up, type }: GenerateParamsType) => GenerateParamsResp;
228
285
  declare const toObjectKey: (id: ObjectKey | ObjectKey[] | undefined) => ObjectKey | undefined;
229
286
  declare const getResultAsArray: (field: DefaultField) => any[] | null;
230
287
  declare const updateArrayItem: (arr: any[], index: number, updater: (item: KeyMap) => KeyMap) => void;
@@ -254,36 +311,4 @@ declare namespace utils {
254
311
  export { utils_combineArrayData as combineArrayData, utils_computeMatchedItemIndex as computeMatchedItemIndex, utils_computeResultLength as computeResultLength, utils_generateDefaultField as generateDefaultField, utils_generateFieldName as generateFieldName, utils_generateRequestParams as generateRequestParams, utils_getObjectDeepValue as getObjectDeepValue, utils_getResultAsArray as getResultAsArray, utils_isArray as isArray, utils_isKeyMap as isKeyMap, utils_isKeyMapArray as isKeyMapArray, utils_isObjectKey as isObjectKey, utils_isObjectKeyArray as isObjectKeyArray, utils_isObjectResult as isObjectResult, utils_isResultObject as isResultObject, utils_searchValueByKey as searchValueByKey, utils_setReactivityField as setReactivityField, utils_stableSerialize as stableSerialize, utils_toObjectKey as toObjectKey, utils_updateArrayItem as updateArrayItem, utils_updateObjectDeepValue as updateObjectDeepValue };
255
312
  }
256
313
 
257
- declare const _default: {
258
- readonly SETTER_TYPE: {
259
- readonly RESET: 0;
260
- readonly MERGE: 1;
261
- };
262
- readonly FETCH_TYPE_ARRAY: readonly ["jump", "sinceId", "page", "seenIds", "auto"];
263
- readonly FETCH_TYPE: {
264
- readonly PAGINATION: "jump";
265
- readonly SINCE_FIRST_OR_END_ID: "sinceId";
266
- readonly SCROLL_LOAD_MORE: "page";
267
- readonly HAS_LOADED_IDS: "seenIds";
268
- readonly AUTO: "auto";
269
- };
270
- readonly CHANGE_TYPE: {
271
- readonly SEARCH_FIELD: "search";
272
- readonly RESET_FIELD: "reset";
273
- readonly RESULT_UPDATE_KV: "update";
274
- readonly RESULT_ADD_AFTER: "push";
275
- readonly RESULT_ADD_BEFORE: "unshift";
276
- readonly RESULT_REMOVE_BY_ID: "delete";
277
- readonly RESULT_INSERT_TO_BEFORE: "insert-before";
278
- readonly RESULT_INSERT_TO_AFTER: "insert-after";
279
- readonly RESULT_LIST_MERGE: "patch";
280
- readonly RESULT_ITEM_MERGE: "merge";
281
- };
282
- readonly FIELD_DATA: {
283
- readonly RESULT_KEY: "result";
284
- readonly EXTRA_KEY: "extra";
285
- };
286
- readonly DEFAULT_UNIQUE_KEY_NAME: "id";
287
- };
288
-
289
314
  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 };
@@ -70,8 +70,29 @@ var FlowList = (function (exports) {
70
70
  var isResultObject = (data) => !isArray(data) && typeof data === "object" && data !== null;
71
71
  var isObjectKey = (value) => typeof value === "string" || typeof value === "number";
72
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
+ var isKeyMapArray = (value) => {
74
+ if (!isArray(value)) return false;
75
+ const len = value.length;
76
+ for (let i = 0; i < len; i++) {
77
+ const item = value[i];
78
+ if (typeof item !== "object" || item === null) {
79
+ return false;
80
+ }
81
+ }
82
+ return true;
83
+ };
84
+ var isObjectKeyArray = (value) => {
85
+ if (!isArray(value)) return false;
86
+ const len = value.length;
87
+ for (let i = 0; i < len; i++) {
88
+ const item = value[i];
89
+ const itemType = typeof item;
90
+ if (itemType !== "string" && itemType !== "number") {
91
+ return false;
92
+ }
93
+ }
94
+ return true;
95
+ };
75
96
  var stableSerialize = (value) => {
76
97
  if (value === null || typeof value !== "object") {
77
98
  return String(value);
@@ -132,16 +153,25 @@ var FlowList = (function (exports) {
132
153
  func,
133
154
  query
134
155
  }) => {
135
- let result = func.id;
136
156
  if (!query) {
137
- return result;
157
+ return func.id;
138
158
  }
139
- const queryObj = query;
140
- const filteredKeys = Object.keys(queryObj).filter((key) => !func.paramsIgnore.includes(key)).sort();
159
+ let result = func.id;
160
+ const keys = Object.keys(query);
161
+ const paramsIgnore = func.paramsIgnore;
162
+ const filteredKeys = [];
163
+ const keysLen = keys.length;
164
+ for (let i = 0; i < keysLen; i++) {
165
+ const key = keys[i];
166
+ if (!paramsIgnore.includes(key)) {
167
+ filteredKeys.push(key);
168
+ }
169
+ }
170
+ filteredKeys.sort();
141
171
  const len = filteredKeys.length;
142
172
  for (let i = 0; i < len; i++) {
143
173
  const key = filteredKeys[i];
144
- const value = queryObj[key];
174
+ const value = query[key];
145
175
  let safeValue;
146
176
  if (typeof value === "object" && value !== null) {
147
177
  safeValue = stableSerialize(value);
@@ -154,19 +184,15 @@ var FlowList = (function (exports) {
154
184
  return result;
155
185
  };
156
186
  var getObjectDeepValue = (field, keys) => {
157
- if (!keys || isArray(keys) && keys.length === 0) {
187
+ if (!keys || Array.isArray(keys) && keys.length === 0)
158
188
  return field;
189
+ const keysArr = Array.isArray(keys) ? keys : keys.split(".");
190
+ let cur = field;
191
+ for (let i = 0, n = keysArr.length; i < n; ++i) {
192
+ if (cur == null || typeof cur !== "object") return void 0;
193
+ cur = cur[keysArr[i]];
159
194
  }
160
- const keysArr = isArray(keys) ? keys : keys.split(".");
161
- let result = field;
162
- const len = keysArr.length;
163
- for (let i = 0; i < len; i++) {
164
- if (result == null || typeof result !== "object") {
165
- return void 0;
166
- }
167
- result = result[keysArr[i]];
168
- }
169
- return result;
195
+ return cur;
170
196
  };
171
197
  var updateObjectDeepValue = (field, changeKey, value) => {
172
198
  if (!changeKey) return;
@@ -205,12 +231,23 @@ var FlowList = (function (exports) {
205
231
  var computeMatchedItemIndex = (itemId, fieldArr, changingKey) => {
206
232
  const stringifiedItemId = String(itemId);
207
233
  const len = fieldArr.length;
208
- for (let i = 0; i < len; i++) {
209
- const item = fieldArr[i];
210
- if (!isKeyMap(item)) continue;
211
- const itemValue = getObjectDeepValue(item, changingKey);
212
- if (String(itemValue) === stringifiedItemId) {
213
- return i;
234
+ const isSimpleKey = !changingKey.includes(".");
235
+ if (isSimpleKey) {
236
+ for (let i = 0; i < len; i++) {
237
+ const item = fieldArr[i];
238
+ if (!isKeyMap(item)) continue;
239
+ if (String(item[changingKey]) === stringifiedItemId) {
240
+ return i;
241
+ }
242
+ }
243
+ } else {
244
+ for (let i = 0; i < len; i++) {
245
+ const item = fieldArr[i];
246
+ if (!isKeyMap(item)) continue;
247
+ const itemValue = getObjectDeepValue(item, changingKey);
248
+ if (String(itemValue) === stringifiedItemId) {
249
+ return i;
250
+ }
214
251
  }
215
252
  }
216
253
  return -1;
@@ -236,7 +273,7 @@ var FlowList = (function (exports) {
236
273
  if (index !== void 0) {
237
274
  const existingItem = fieldArray[index];
238
275
  if (isKeyMap(existingItem)) {
239
- Object.assign(existingItem, col);
276
+ fieldArray[index] = { ...existingItem, ...col };
240
277
  }
241
278
  }
242
279
  }
@@ -250,7 +287,7 @@ var FlowList = (function (exports) {
250
287
  if (index !== void 0) {
251
288
  const existingItem = fieldArray[index];
252
289
  if (isKeyMap(existingItem)) {
253
- Object.assign(existingItem, col);
290
+ fieldArray[index] = { ...existingItem, ...col };
254
291
  }
255
292
  }
256
293
  }
@@ -266,40 +303,29 @@ var FlowList = (function (exports) {
266
303
  if (isArray(value)) {
267
304
  const current = fieldAny[key];
268
305
  const currentArr = isArray(current) ? current : [];
269
- const newValue = insertBefore ? [...value, ...currentArr] : [...currentArr, ...value];
270
- fieldAny[key] = newValue;
306
+ fieldAny[key] = insertBefore ? value.concat(currentArr) : currentArr.concat(value);
271
307
  } else {
272
308
  fieldAny[key] = value;
273
309
  }
274
310
  return;
275
311
  }
276
312
  const resultField = field.result;
277
- const valueObj = value;
278
313
  if (isArray(value)) {
279
- const currentArr = isArray(resultField) ? resultField : [];
280
314
  const valueArr = value;
281
- if (insertBefore) {
282
- if (valueArr.length === 0) return;
283
- if (currentArr.length === 0) {
284
- field.result = valueArr;
285
- return;
286
- }
287
- field.result = valueArr.concat(currentArr);
288
- } else {
289
- if (valueArr.length === 0) return;
290
- if (currentArr.length === 0) {
291
- field.result = valueArr;
292
- return;
293
- }
294
- field.result = currentArr.concat(valueArr);
315
+ const valueLen = valueArr.length;
316
+ if (valueLen === 0) return;
317
+ const currentArr = isArray(resultField) ? resultField : [];
318
+ const currentLen = currentArr.length;
319
+ if (currentLen === 0) {
320
+ field.result = valueArr;
321
+ return;
295
322
  }
323
+ field.result = insertBefore ? valueArr.concat(currentArr) : currentArr.concat(valueArr);
296
324
  return;
297
325
  }
326
+ const valueObj = value;
298
327
  let target = resultField;
299
- if (isArray(resultField)) {
300
- target = {};
301
- field.result = target;
302
- } else if (typeof resultField !== "object" || resultField === null) {
328
+ if (isArray(resultField) || typeof resultField !== "object" || resultField === null) {
303
329
  target = {};
304
330
  field.result = target;
305
331
  }
@@ -310,10 +336,10 @@ var FlowList = (function (exports) {
310
336
  const existing = target[subKey];
311
337
  const incoming = valueObj[subKey];
312
338
  if (existing !== void 0) {
313
- if (insertBefore) {
314
- target[subKey] = isArray(incoming) && isArray(existing) ? [...incoming, ...existing] : incoming;
339
+ if (isArray(existing) && isArray(incoming)) {
340
+ target[subKey] = insertBefore ? incoming.concat(existing) : existing.concat(incoming);
315
341
  } else {
316
- target[subKey] = isArray(existing) && isArray(incoming) ? [...existing, ...incoming] : incoming;
342
+ target[subKey] = incoming;
317
343
  }
318
344
  } else {
319
345
  target[subKey] = incoming;
@@ -354,6 +380,7 @@ var FlowList = (function (exports) {
354
380
  field,
355
381
  uniqueKey = enum_default.DEFAULT_UNIQUE_KEY_NAME,
356
382
  query = {},
383
+ is_up = false,
357
384
  type
358
385
  }) => {
359
386
  const result = { ...query };
@@ -366,11 +393,11 @@ var FlowList = (function (exports) {
366
393
  if (type === enum_default.FETCH_TYPE.AUTO) {
367
394
  if (isArray(fieldResultAny)) {
368
395
  result.seen_ids = getSeenIdsString(fieldResultAny, uniqueKey);
369
- const targetIndex = query.is_up ? 0 : fieldResultAny.length - 1;
396
+ const targetIndex = is_up ? 0 : fieldResultAny.length - 1;
370
397
  const targetItem = fieldResultAny[targetIndex];
371
398
  result.since_id = getSafeObjectKey(targetItem);
372
399
  }
373
- result.is_up = query.is_up ? 1 : 0;
400
+ result.is_up = is_up ? 1 : 0;
374
401
  result.page = typeof query.page === "number" ? query.page : field.page + 1;
375
402
  } else if (type === enum_default.FETCH_TYPE.HAS_LOADED_IDS) {
376
403
  if (isArray(fieldResultAny)) {
@@ -378,11 +405,11 @@ var FlowList = (function (exports) {
378
405
  }
379
406
  } else if (type === enum_default.FETCH_TYPE.SINCE_FIRST_OR_END_ID) {
380
407
  if (isArray(fieldResultAny)) {
381
- const targetIndex = query.is_up ? 0 : fieldResultAny.length - 1;
408
+ const targetIndex = is_up ? 0 : fieldResultAny.length - 1;
382
409
  const targetItem = fieldResultAny[targetIndex];
383
410
  result.since_id = getSafeObjectKey(targetItem);
384
411
  }
385
- result.is_up = query.is_up ? 1 : 0;
412
+ result.is_up = is_up ? 1 : 0;
386
413
  } else if (type === enum_default.FETCH_TYPE.PAGINATION) {
387
414
  result.page = typeof query.page === "number" ? query.page : void 0;
388
415
  } else if (type === enum_default.FETCH_TYPE.SCROLL_LOAD_MORE) {
@@ -391,14 +418,14 @@ var FlowList = (function (exports) {
391
418
  } else {
392
419
  if (type === enum_default.FETCH_TYPE.AUTO) {
393
420
  result.seen_ids = "";
394
- result.since_id = isObjectKey(query.sinceId) ? query.sinceId : query.is_up ? 999999999 : 0;
395
- result.is_up = query.is_up ? 1 : 0;
421
+ result.since_id = isObjectKey(query.sinceId) ? query.sinceId : "";
422
+ result.is_up = is_up ? 1 : 0;
396
423
  result.page = typeof query.page === "number" ? query.page : field.page || 1;
397
424
  } else if (type === enum_default.FETCH_TYPE.HAS_LOADED_IDS) {
398
425
  result.seen_ids = "";
399
426
  } else if (type === enum_default.FETCH_TYPE.SINCE_FIRST_OR_END_ID) {
400
- result.since_id = isObjectKey(query.sinceId) ? query.sinceId : query.is_up ? 999999999 : 0;
401
- result.is_up = query.is_up ? 1 : 0;
427
+ result.since_id = isObjectKey(query.sinceId) ? query.sinceId : "";
428
+ result.is_up = is_up ? 1 : 0;
402
429
  } else if (type === enum_default.FETCH_TYPE.PAGINATION) {
403
430
  result.page = typeof query.page === "number" ? query.page : field.page;
404
431
  } else if (type === enum_default.FETCH_TYPE.SCROLL_LOAD_MORE) {
@@ -527,9 +554,9 @@ var FlowList = (function (exports) {
527
554
  id: options.id,
528
555
  type: options.type || enum_default.FETCH_TYPE.SCROLL_LOAD_MORE,
529
556
  uniqueKey: options.uniqueKey || enum_default.DEFAULT_UNIQUE_KEY_NAME,
557
+ is_up: options.is_up || false,
530
558
  paramsIgnore: [
531
559
  "page",
532
- "is_up",
533
560
  "since_id",
534
561
  "seen_ids",
535
562
  "__refresh__",
@@ -576,6 +603,7 @@ var FlowList = (function (exports) {
576
603
  field: generateDefaultField({ ...fieldData, fetched: false }),
577
604
  uniqueKey: func.uniqueKey,
578
605
  type: func.type,
606
+ is_up: func.is_up,
579
607
  query
580
608
  });
581
609
  const executeFetch = () => {
@@ -641,6 +669,7 @@ var FlowList = (function (exports) {
641
669
  field: fieldData,
642
670
  uniqueKey: func.uniqueKey,
643
671
  type,
672
+ is_up: func.is_up,
644
673
  query
645
674
  });
646
675
  if (fieldData.extra) params.extra = fieldData.extra;
@@ -657,7 +686,7 @@ var FlowList = (function (exports) {
657
686
  type,
658
687
  fieldName,
659
688
  page: params.page || 0,
660
- insertBefore: !!query?.is_up
689
+ insertBefore: func.is_up
661
690
  }).then(() => {
662
691
  callback?.({ params, data, refresh: false });
663
692
  resolve();
@@ -697,7 +726,11 @@ var FlowList = (function (exports) {
697
726
  fieldData[enum_default.FIELD_DATA.RESULT_KEY]
698
727
  );
699
728
  const newFieldData = { ...fieldData };
700
- const resultArray = getResultAsArray(newFieldData);
729
+ let resultArray = getResultAsArray(fieldData);
730
+ if (resultArray) {
731
+ resultArray = [...resultArray];
732
+ newFieldData.result = resultArray;
733
+ }
701
734
  if (method === enum_default.CHANGE_TYPE.SEARCH_FIELD) {
702
735
  const objectKeyId = toObjectKey(_id);
703
736
  if (objectKeyId === void 0) {
@@ -720,7 +753,9 @@ var FlowList = (function (exports) {
720
753
  _uniqueKey
721
754
  );
722
755
  if (matchedIndex >= 0 && isKeyMap(resultArray[matchedIndex])) {
723
- updateObjectDeepValue(resultArray[matchedIndex], _changeKey, value);
756
+ const newItem = { ...resultArray[matchedIndex] };
757
+ updateObjectDeepValue(newItem, _changeKey, value);
758
+ resultArray[matchedIndex] = newItem;
724
759
  }
725
760
  }
726
761
  resolve(null);
@@ -752,7 +787,7 @@ var FlowList = (function (exports) {
752
787
  } else {
753
788
  let modifyValue;
754
789
  if (_changeKey === enum_default.FIELD_DATA.RESULT_KEY) {
755
- modifyValue = newFieldData.result;
790
+ modifyValue = resultArray || newFieldData.result;
756
791
  } else if (_changeKey === enum_default.FIELD_DATA.EXTRA_KEY) {
757
792
  modifyValue = newFieldData.extra;
758
793
  } else {
@@ -777,7 +812,9 @@ var FlowList = (function (exports) {
777
812
  case enum_default.CHANGE_TYPE.RESULT_REMOVE_BY_ID:
778
813
  if (isKeyMapArray(modifyValue)) {
779
814
  if (matchedIndex >= 0) {
780
- modifyValue.splice(matchedIndex, 1);
815
+ const newArray = [...modifyValue];
816
+ newArray.splice(matchedIndex, 1);
817
+ modifyValue = newArray;
781
818
  } else if (isObjectKeyArray(_id)) {
782
819
  const idSet = new Set(_id);
783
820
  modifyValue = modifyValue.filter((item) => {
@@ -789,18 +826,23 @@ var FlowList = (function (exports) {
789
826
  break;
790
827
  case enum_default.CHANGE_TYPE.RESULT_INSERT_TO_BEFORE:
791
828
  if (isArray(modifyValue) && matchedIndex >= 0) {
792
- modifyValue.splice(matchedIndex, 0, value);
829
+ const newArray = [...modifyValue];
830
+ newArray.splice(matchedIndex, 0, value);
831
+ modifyValue = newArray;
793
832
  }
794
833
  break;
795
834
  case enum_default.CHANGE_TYPE.RESULT_INSERT_TO_AFTER:
796
835
  if (isArray(modifyValue) && matchedIndex >= 0) {
797
- modifyValue.splice(matchedIndex + 1, 0, value);
836
+ const newArray = [...modifyValue];
837
+ newArray.splice(matchedIndex + 1, 0, value);
838
+ modifyValue = newArray;
798
839
  }
799
840
  break;
800
841
  case enum_default.CHANGE_TYPE.RESULT_LIST_MERGE:
801
842
  if (isKeyMapArray(modifyValue)) {
843
+ const newArray = [...modifyValue];
802
844
  if (isKeyMapArray(value)) {
803
- combineArrayData(modifyValue, value, _uniqueKey);
845
+ combineArrayData(newArray, value, _uniqueKey);
804
846
  } else if (isKeyMap(value)) {
805
847
  const valueAsRecord = {};
806
848
  for (const [k, v] of Object.entries(value)) {
@@ -808,8 +850,9 @@ var FlowList = (function (exports) {
808
850
  valueAsRecord[k] = v;
809
851
  }
810
852
  }
811
- combineArrayData(modifyValue, valueAsRecord, _uniqueKey);
853
+ combineArrayData(newArray, valueAsRecord, _uniqueKey);
812
854
  }
855
+ modifyValue = newArray;
813
856
  }
814
857
  break;
815
858
  default: