@flowlist/js-core 1.7.4 → 2.0.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.ts +4 -1
- package/dist/js-core.es.js +564 -1
- package/dist/js-core.umd.js +1 -1
- package/package.json +17 -16
- package/src/actions.ts +2 -39
- package/src/setters.ts +0 -27
- package/src/types.ts +6 -27
- package/src/utils.ts +4 -2
- package/dist/src/actions.d.ts +0 -5
- package/dist/src/enum.d.ts +0 -32
- package/dist/src/index.d.ts +0 -4
- package/dist/src/setters.d.ts +0 -3
- package/dist/src/types.d.ts +0 -118
- package/dist/src/utils.d.ts +0 -58
- package/dist/tests/unit/api.d.ts +0 -68
- package/dist/tests/unit/env.d.ts +0 -20
- package/dist/tests/unit/item-factory.d.ts +0 -23
package/dist/index.d.ts
CHANGED
package/dist/js-core.es.js
CHANGED
|
@@ -1 +1,564 @@
|
|
|
1
|
-
var
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
const FETCH_TYPE_ARRAY = ["jump", "sinceId", "page", "seenIds", "auto"];
|
|
21
|
+
var ENUM = {
|
|
22
|
+
SETTER_TYPE: {
|
|
23
|
+
RESET: 0,
|
|
24
|
+
MERGE: 1
|
|
25
|
+
},
|
|
26
|
+
FETCH_TYPE_ARRAY,
|
|
27
|
+
FETCH_TYPE: {
|
|
28
|
+
PAGINATION: FETCH_TYPE_ARRAY[0],
|
|
29
|
+
SINCE_FIRST_OR_END_ID: FETCH_TYPE_ARRAY[1],
|
|
30
|
+
SCROLL_LOAD_MORE: FETCH_TYPE_ARRAY[2],
|
|
31
|
+
HAS_LOADED_IDS: FETCH_TYPE_ARRAY[3],
|
|
32
|
+
AUTO: FETCH_TYPE_ARRAY[4]
|
|
33
|
+
},
|
|
34
|
+
CHANGE_TYPE: {
|
|
35
|
+
SEARCH_FIELD: "search",
|
|
36
|
+
RESET_FIELD: "reset",
|
|
37
|
+
RESULT_UPDATE_KV: "update",
|
|
38
|
+
RESULT_ADD_AFTER: "push",
|
|
39
|
+
RESULT_ADD_BEFORE: "unshift",
|
|
40
|
+
RESULT_REMOVE_BY_ID: "delete",
|
|
41
|
+
RESULT_INSERT_TO_BEFORE: "insert-before",
|
|
42
|
+
RESULT_INSERT_TO_AFTER: "insert-after",
|
|
43
|
+
RESULT_LIST_MERGE: "patch",
|
|
44
|
+
RESULT_ITEM_MERGE: "merge"
|
|
45
|
+
},
|
|
46
|
+
FIELD_DATA: {
|
|
47
|
+
RESULT_KEY: "result",
|
|
48
|
+
EXTRA_KEY: "extra"
|
|
49
|
+
},
|
|
50
|
+
DEFAULT_UNIQUE_KEY_NAME: "id"
|
|
51
|
+
};
|
|
52
|
+
const generateDefaultField = (opts = {}) => __spreadValues(__spreadValues({}, {
|
|
53
|
+
result: [],
|
|
54
|
+
noMore: false,
|
|
55
|
+
nothing: false,
|
|
56
|
+
loading: false,
|
|
57
|
+
error: null,
|
|
58
|
+
extra: null,
|
|
59
|
+
fetched: false,
|
|
60
|
+
page: 0,
|
|
61
|
+
total: 0
|
|
62
|
+
}), opts);
|
|
63
|
+
const generateFieldName = ({
|
|
64
|
+
func,
|
|
65
|
+
type,
|
|
66
|
+
query = {}
|
|
67
|
+
}) => {
|
|
68
|
+
func = typeof func === "string" ? func : `api-${Math.random().toString(36).substring(2)}`;
|
|
69
|
+
type = type || "auto";
|
|
70
|
+
let result = `${func}-${type}`;
|
|
71
|
+
Object.keys(query).filter((_) => !~["undefined", "object", "function"].indexOf(typeof query[_]) && !~[
|
|
72
|
+
"page",
|
|
73
|
+
"is_up",
|
|
74
|
+
"since_id",
|
|
75
|
+
"seen_ids",
|
|
76
|
+
"__refresh__",
|
|
77
|
+
"__reload__"
|
|
78
|
+
].indexOf(_)).sort().forEach((key) => {
|
|
79
|
+
result += `-${key}-${query[key]}`;
|
|
80
|
+
});
|
|
81
|
+
return result;
|
|
82
|
+
};
|
|
83
|
+
const getObjectDeepValue = (field, keys) => {
|
|
84
|
+
if (!keys) {
|
|
85
|
+
return field || "";
|
|
86
|
+
}
|
|
87
|
+
let result = field || "";
|
|
88
|
+
const keysArr = isArray(keys) ? keys : keys.split(".");
|
|
89
|
+
keysArr.forEach((key) => {
|
|
90
|
+
result = result[key];
|
|
91
|
+
});
|
|
92
|
+
return result || "";
|
|
93
|
+
};
|
|
94
|
+
const updateObjectDeepValue = (field, changeKey, value) => {
|
|
95
|
+
if (/\./.test(changeKey)) {
|
|
96
|
+
const keys = changeKey.split(".");
|
|
97
|
+
const prefix = keys.pop();
|
|
98
|
+
let result = field;
|
|
99
|
+
keys.forEach((key) => {
|
|
100
|
+
result = result[key];
|
|
101
|
+
});
|
|
102
|
+
result[prefix] = value;
|
|
103
|
+
} else {
|
|
104
|
+
field[changeKey] = value;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const searchValueByKey = (result, id, key) => {
|
|
108
|
+
if (isArray(result)) {
|
|
109
|
+
const index = computeMatchedItemIndex(id, result, key);
|
|
110
|
+
if (index < 0) {
|
|
111
|
+
return void 0;
|
|
112
|
+
}
|
|
113
|
+
return result[index];
|
|
114
|
+
}
|
|
115
|
+
return result[id];
|
|
116
|
+
};
|
|
117
|
+
const computeMatchedItemIndex = (itemId, fieldArr, changingKey) => {
|
|
118
|
+
let s = -1;
|
|
119
|
+
for (let i = 0; i < fieldArr.length; i++) {
|
|
120
|
+
if (getObjectDeepValue(fieldArr[i], changingKey.toString()).toString() === (itemId || "").toString()) {
|
|
121
|
+
s = i;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return s;
|
|
126
|
+
};
|
|
127
|
+
const combineArrayData = (fieldArray, value, changingKey) => {
|
|
128
|
+
if (isArray(value)) {
|
|
129
|
+
value.forEach((col) => {
|
|
130
|
+
const stringifyId = getObjectDeepValue(col, changingKey).toString();
|
|
131
|
+
fieldArray.forEach((item, index) => {
|
|
132
|
+
if (getObjectDeepValue(item, changingKey).toString() === stringifyId) {
|
|
133
|
+
fieldArray[index] = __spreadValues(__spreadValues({}, item), col);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
} else {
|
|
138
|
+
Object.keys(value).forEach((uniqueId) => {
|
|
139
|
+
const stringifyId = (uniqueId || "").toString();
|
|
140
|
+
fieldArray.forEach((item, index) => {
|
|
141
|
+
if (getObjectDeepValue(item, changingKey).toString() === stringifyId) {
|
|
142
|
+
fieldArray[index] = __spreadValues(__spreadValues({}, item), value[uniqueId]);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
const isArray = (data) => Object.prototype.toString.call(data) === "[object Array]";
|
|
149
|
+
const setReactivityField = (field, key, value, type, insertBefore) => {
|
|
150
|
+
if (type === ENUM.FETCH_TYPE.PAGINATION) {
|
|
151
|
+
field[key] = value;
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (isArray(value)) {
|
|
155
|
+
field[key] = insertBefore ? value.concat(field[key] || []) : (field[key] || []).concat(value);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (key !== ENUM.FIELD_DATA.RESULT_KEY) {
|
|
159
|
+
field[key] = value;
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (isArray(field[key])) {
|
|
163
|
+
field[key] = {};
|
|
164
|
+
}
|
|
165
|
+
Object.keys(value).forEach((subKey) => {
|
|
166
|
+
field[key][subKey] = field[key][subKey] ? insertBefore ? value[subKey].concat(field[key][subKey]) : field[key][subKey].concat(value[subKey]) : value[subKey];
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
const computeResultLength = (data) => {
|
|
170
|
+
let result = 0;
|
|
171
|
+
if (isArray(data)) {
|
|
172
|
+
result = data.length;
|
|
173
|
+
} else {
|
|
174
|
+
Object.keys(data).forEach((key) => {
|
|
175
|
+
result += data[key].length;
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
return result;
|
|
179
|
+
};
|
|
180
|
+
const generateRequestParams = ({
|
|
181
|
+
field,
|
|
182
|
+
uniqueKey,
|
|
183
|
+
query,
|
|
184
|
+
type
|
|
185
|
+
}) => {
|
|
186
|
+
const result = {};
|
|
187
|
+
query = query || {};
|
|
188
|
+
if (field.fetched) {
|
|
189
|
+
const changing = uniqueKey || ENUM.DEFAULT_UNIQUE_KEY_NAME;
|
|
190
|
+
if (type === ENUM.FETCH_TYPE.AUTO) {
|
|
191
|
+
result.seen_ids = field.result.map((_) => getObjectDeepValue(_, changing)).join(",");
|
|
192
|
+
result.since_id = getObjectDeepValue(field.result[query.is_up ? 0 : field.result.length - 1], changing);
|
|
193
|
+
result.is_up = query.is_up ? 1 : 0;
|
|
194
|
+
result.page = query.page || field.page + 1;
|
|
195
|
+
} else if (type === ENUM.FETCH_TYPE.HAS_LOADED_IDS) {
|
|
196
|
+
result.seen_ids = field.result.map((_) => getObjectDeepValue(_, changing)).join(",");
|
|
197
|
+
} else if (type === ENUM.FETCH_TYPE.SINCE_FIRST_OR_END_ID) {
|
|
198
|
+
result.since_id = getObjectDeepValue(field.result[query.is_up ? 0 : field.result.length - 1], changing);
|
|
199
|
+
result.is_up = query.is_up ? 1 : 0;
|
|
200
|
+
} else if (type === ENUM.FETCH_TYPE.PAGINATION) {
|
|
201
|
+
result.page = query.page;
|
|
202
|
+
} else if (type === ENUM.FETCH_TYPE.SCROLL_LOAD_MORE) {
|
|
203
|
+
result.page = field.page + 1;
|
|
204
|
+
}
|
|
205
|
+
} else {
|
|
206
|
+
if (type === ENUM.FETCH_TYPE.AUTO) {
|
|
207
|
+
result.seen_ids = "";
|
|
208
|
+
result.since_id = query.sinceId || (query.is_up ? 999999999 : 0);
|
|
209
|
+
result.is_up = query.is_up ? 1 : 0;
|
|
210
|
+
result.page = query.page || field.page || 1;
|
|
211
|
+
} else if (type === ENUM.FETCH_TYPE.HAS_LOADED_IDS) {
|
|
212
|
+
result.seen_ids = "";
|
|
213
|
+
} else if (type === ENUM.FETCH_TYPE.SINCE_FIRST_OR_END_ID) {
|
|
214
|
+
result.since_id = query.sinceId || (query.is_up ? 999999999 : 0);
|
|
215
|
+
result.is_up = query.is_up ? 1 : 0;
|
|
216
|
+
} else if (type === ENUM.FETCH_TYPE.PAGINATION) {
|
|
217
|
+
result.page = query.page || field.page;
|
|
218
|
+
} else if (type === ENUM.FETCH_TYPE.SCROLL_LOAD_MORE) {
|
|
219
|
+
result.page = 1;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return __spreadValues(__spreadValues({}, query), result);
|
|
223
|
+
};
|
|
224
|
+
var utils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
225
|
+
__proto__: null,
|
|
226
|
+
generateDefaultField,
|
|
227
|
+
generateFieldName,
|
|
228
|
+
getObjectDeepValue,
|
|
229
|
+
updateObjectDeepValue,
|
|
230
|
+
searchValueByKey,
|
|
231
|
+
computeMatchedItemIndex,
|
|
232
|
+
combineArrayData,
|
|
233
|
+
isArray,
|
|
234
|
+
setReactivityField,
|
|
235
|
+
computeResultLength,
|
|
236
|
+
generateRequestParams
|
|
237
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
238
|
+
const SET_DATA = ({
|
|
239
|
+
getter,
|
|
240
|
+
setter,
|
|
241
|
+
data,
|
|
242
|
+
fieldName,
|
|
243
|
+
type,
|
|
244
|
+
page,
|
|
245
|
+
insertBefore
|
|
246
|
+
}) => {
|
|
247
|
+
return new Promise((resolve, reject) => {
|
|
248
|
+
const fieldData = getter(fieldName);
|
|
249
|
+
if (!fieldData) {
|
|
250
|
+
reject();
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
const { result, extra } = data;
|
|
254
|
+
const isEmpty = computeResultLength(result) === 0;
|
|
255
|
+
fieldData.nothing = fieldData.fetched ? false : isEmpty;
|
|
256
|
+
fieldData.fetched = true;
|
|
257
|
+
fieldData.total = data.total || 0;
|
|
258
|
+
if (type === ENUM.FETCH_TYPE.PAGINATION) {
|
|
259
|
+
fieldData.noMore = false;
|
|
260
|
+
fieldData.page = +page;
|
|
261
|
+
} else {
|
|
262
|
+
fieldData.noMore = data.no_more || isEmpty;
|
|
263
|
+
fieldData.page = fieldData.page + 1;
|
|
264
|
+
}
|
|
265
|
+
fieldData.loading = false;
|
|
266
|
+
setReactivityField(fieldData, ENUM.FIELD_DATA.RESULT_KEY, result, type, insertBefore);
|
|
267
|
+
extra && setReactivityField(fieldData, ENUM.FIELD_DATA.EXTRA_KEY, extra, type, insertBefore);
|
|
268
|
+
setter({
|
|
269
|
+
key: fieldName,
|
|
270
|
+
type: ENUM.SETTER_TYPE.RESET,
|
|
271
|
+
value: fieldData,
|
|
272
|
+
callback: () => {
|
|
273
|
+
resolve(null);
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
};
|
|
278
|
+
const SET_ERROR = ({ setter, fieldName, error }) => {
|
|
279
|
+
setter({
|
|
280
|
+
key: fieldName,
|
|
281
|
+
type: ENUM.SETTER_TYPE.MERGE,
|
|
282
|
+
value: {
|
|
283
|
+
error,
|
|
284
|
+
loading: false
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
};
|
|
288
|
+
const initState = ({
|
|
289
|
+
getter,
|
|
290
|
+
setter,
|
|
291
|
+
func,
|
|
292
|
+
type,
|
|
293
|
+
query = {},
|
|
294
|
+
opts = {}
|
|
295
|
+
}) => {
|
|
296
|
+
return new Promise((resolve) => {
|
|
297
|
+
const fieldName = generateFieldName({ func, type, query });
|
|
298
|
+
const fieldData = getter(fieldName);
|
|
299
|
+
if (fieldData) {
|
|
300
|
+
resolve(null);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
setter({
|
|
304
|
+
key: fieldName,
|
|
305
|
+
type: ENUM.SETTER_TYPE.RESET,
|
|
306
|
+
value: generateDefaultField(opts),
|
|
307
|
+
callback: () => {
|
|
308
|
+
resolve(null);
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
};
|
|
313
|
+
const initData = ({
|
|
314
|
+
getter,
|
|
315
|
+
setter,
|
|
316
|
+
func,
|
|
317
|
+
type,
|
|
318
|
+
query = {},
|
|
319
|
+
api,
|
|
320
|
+
uniqueKey,
|
|
321
|
+
callback
|
|
322
|
+
}) => new Promise((resolve, reject) => {
|
|
323
|
+
const fieldName = generateFieldName({ func, type, query });
|
|
324
|
+
const fieldData = getter(fieldName);
|
|
325
|
+
const doRefresh = !!query.__refresh__;
|
|
326
|
+
const needReset = !!query.__reload__;
|
|
327
|
+
if (fieldData && fieldData.error && !doRefresh) {
|
|
328
|
+
return resolve(null);
|
|
329
|
+
}
|
|
330
|
+
if (fieldData && fieldData.loading) {
|
|
331
|
+
return resolve(null);
|
|
332
|
+
}
|
|
333
|
+
const dontFetch = fieldData && fieldData.fetched && !doRefresh;
|
|
334
|
+
if (dontFetch) {
|
|
335
|
+
return resolve(null);
|
|
336
|
+
}
|
|
337
|
+
const params = generateRequestParams({
|
|
338
|
+
field: __spreadProps(__spreadValues({}, fieldData), {
|
|
339
|
+
fetched: false
|
|
340
|
+
}),
|
|
341
|
+
uniqueKey,
|
|
342
|
+
query,
|
|
343
|
+
type
|
|
344
|
+
});
|
|
345
|
+
const getData = () => {
|
|
346
|
+
const loadData = () => new Promise((res) => {
|
|
347
|
+
const getDataFromAPI = () => {
|
|
348
|
+
const funcCaller = typeof func === "string" ? api[func] : func;
|
|
349
|
+
funcCaller(params).then(res).catch((error) => {
|
|
350
|
+
SET_ERROR({ setter, fieldName, error });
|
|
351
|
+
reject(error);
|
|
352
|
+
});
|
|
353
|
+
};
|
|
354
|
+
getDataFromAPI();
|
|
355
|
+
});
|
|
356
|
+
loadData().then((data) => {
|
|
357
|
+
const setData = () => {
|
|
358
|
+
SET_DATA({
|
|
359
|
+
getter,
|
|
360
|
+
setter,
|
|
361
|
+
data,
|
|
362
|
+
fieldName,
|
|
363
|
+
type,
|
|
364
|
+
page: params.page || 0,
|
|
365
|
+
insertBefore: false
|
|
366
|
+
}).then(() => {
|
|
367
|
+
if (callback) {
|
|
368
|
+
callback({
|
|
369
|
+
params,
|
|
370
|
+
data,
|
|
371
|
+
refresh: doRefresh
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
resolve(null);
|
|
375
|
+
});
|
|
376
|
+
};
|
|
377
|
+
if (needReset) {
|
|
378
|
+
setter({
|
|
379
|
+
key: fieldName,
|
|
380
|
+
type: ENUM.SETTER_TYPE.RESET,
|
|
381
|
+
value: generateDefaultField(),
|
|
382
|
+
callback: setData
|
|
383
|
+
});
|
|
384
|
+
} else {
|
|
385
|
+
setData();
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
};
|
|
389
|
+
if (!dontFetch && !needReset) {
|
|
390
|
+
setter({
|
|
391
|
+
key: fieldName,
|
|
392
|
+
type: ENUM.SETTER_TYPE.RESET,
|
|
393
|
+
value: __spreadProps(__spreadValues({}, generateDefaultField()), {
|
|
394
|
+
loading: true,
|
|
395
|
+
error: null
|
|
396
|
+
}),
|
|
397
|
+
callback: getData
|
|
398
|
+
});
|
|
399
|
+
} else {
|
|
400
|
+
getData();
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
const loadMore = ({
|
|
404
|
+
getter,
|
|
405
|
+
setter,
|
|
406
|
+
query = {},
|
|
407
|
+
type,
|
|
408
|
+
func,
|
|
409
|
+
api,
|
|
410
|
+
uniqueKey,
|
|
411
|
+
errorRetry,
|
|
412
|
+
callback
|
|
413
|
+
}) => new Promise((resolve, reject) => {
|
|
414
|
+
const fieldName = generateFieldName({ func, type, query });
|
|
415
|
+
const fieldData = getter(fieldName);
|
|
416
|
+
if (!fieldData) {
|
|
417
|
+
return resolve(null);
|
|
418
|
+
}
|
|
419
|
+
if (fieldData.loading) {
|
|
420
|
+
return resolve(null);
|
|
421
|
+
}
|
|
422
|
+
if (fieldData.nothing) {
|
|
423
|
+
return resolve(null);
|
|
424
|
+
}
|
|
425
|
+
if (fieldData.noMore && !errorRetry) {
|
|
426
|
+
return resolve(null);
|
|
427
|
+
}
|
|
428
|
+
if (type === ENUM.FETCH_TYPE.PAGINATION && +query.page === fieldData.page) {
|
|
429
|
+
return resolve(null);
|
|
430
|
+
}
|
|
431
|
+
let loadingState;
|
|
432
|
+
if (type === ENUM.FETCH_TYPE.PAGINATION) {
|
|
433
|
+
loadingState = {
|
|
434
|
+
loading: true,
|
|
435
|
+
error: null,
|
|
436
|
+
[ENUM.FIELD_DATA.RESULT_KEY]: [],
|
|
437
|
+
[ENUM.FIELD_DATA.EXTRA_KEY]: null
|
|
438
|
+
};
|
|
439
|
+
} else {
|
|
440
|
+
loadingState = {
|
|
441
|
+
loading: true,
|
|
442
|
+
error: null
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
const params = generateRequestParams({
|
|
446
|
+
field: fieldData,
|
|
447
|
+
uniqueKey,
|
|
448
|
+
query,
|
|
449
|
+
type
|
|
450
|
+
});
|
|
451
|
+
params[ENUM.FIELD_DATA.EXTRA_KEY] = fieldData[ENUM.FIELD_DATA.EXTRA_KEY];
|
|
452
|
+
const getData = () => {
|
|
453
|
+
const funcCaller = typeof func === "string" ? api[func] : func;
|
|
454
|
+
funcCaller(params).then((data) => {
|
|
455
|
+
SET_DATA({
|
|
456
|
+
getter,
|
|
457
|
+
setter,
|
|
458
|
+
data,
|
|
459
|
+
fieldName,
|
|
460
|
+
type,
|
|
461
|
+
page: params.page || 0,
|
|
462
|
+
insertBefore: !!query.is_up
|
|
463
|
+
}).then(() => {
|
|
464
|
+
if (callback) {
|
|
465
|
+
callback({
|
|
466
|
+
params,
|
|
467
|
+
data,
|
|
468
|
+
refresh: false
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
resolve(null);
|
|
472
|
+
});
|
|
473
|
+
}).catch((error) => {
|
|
474
|
+
SET_ERROR({ setter, fieldName, error });
|
|
475
|
+
reject(error);
|
|
476
|
+
});
|
|
477
|
+
};
|
|
478
|
+
setter({
|
|
479
|
+
key: fieldName,
|
|
480
|
+
type: ENUM.SETTER_TYPE.MERGE,
|
|
481
|
+
value: loadingState,
|
|
482
|
+
callback: getData
|
|
483
|
+
});
|
|
484
|
+
});
|
|
485
|
+
const updateState = ({
|
|
486
|
+
getter,
|
|
487
|
+
setter,
|
|
488
|
+
type,
|
|
489
|
+
func,
|
|
490
|
+
query = {},
|
|
491
|
+
method,
|
|
492
|
+
value,
|
|
493
|
+
id,
|
|
494
|
+
uniqueKey,
|
|
495
|
+
changeKey
|
|
496
|
+
}) => {
|
|
497
|
+
return new Promise((resolve, reject) => {
|
|
498
|
+
const fieldName = generateFieldName({ func, type, query });
|
|
499
|
+
const fieldData = getter(fieldName);
|
|
500
|
+
if (!fieldData) {
|
|
501
|
+
reject();
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
const _id = id || "";
|
|
505
|
+
const _uniqueKey = uniqueKey || ENUM.DEFAULT_UNIQUE_KEY_NAME;
|
|
506
|
+
const _changeKey = changeKey || ENUM.FIELD_DATA.RESULT_KEY;
|
|
507
|
+
const beforeLength = computeResultLength(fieldData[ENUM.FIELD_DATA.RESULT_KEY]);
|
|
508
|
+
if (method === ENUM.CHANGE_TYPE.SEARCH_FIELD) {
|
|
509
|
+
resolve(searchValueByKey(fieldData[ENUM.FIELD_DATA.RESULT_KEY], _id, _uniqueKey));
|
|
510
|
+
} else if (method === ENUM.CHANGE_TYPE.RESULT_UPDATE_KV) {
|
|
511
|
+
const matchedIndex = computeMatchedItemIndex(_id, fieldData[ENUM.FIELD_DATA.RESULT_KEY], _uniqueKey);
|
|
512
|
+
updateObjectDeepValue(fieldData[ENUM.FIELD_DATA.RESULT_KEY][matchedIndex], _changeKey, value);
|
|
513
|
+
} else if (method === ENUM.CHANGE_TYPE.RESULT_ITEM_MERGE) {
|
|
514
|
+
const matchedIndex = computeMatchedItemIndex(_id, fieldData[ENUM.FIELD_DATA.RESULT_KEY], _uniqueKey);
|
|
515
|
+
fieldData[ENUM.FIELD_DATA.RESULT_KEY][matchedIndex] = __spreadValues(__spreadValues({}, fieldData[ENUM.FIELD_DATA.RESULT_KEY][matchedIndex]), value);
|
|
516
|
+
} else if (method === ENUM.CHANGE_TYPE.RESET_FIELD) {
|
|
517
|
+
updateObjectDeepValue(fieldData, _changeKey, value);
|
|
518
|
+
} else {
|
|
519
|
+
let modifyValue = getObjectDeepValue(fieldData, _changeKey);
|
|
520
|
+
const matchedIndex = computeMatchedItemIndex(_id, modifyValue, _uniqueKey);
|
|
521
|
+
switch (method) {
|
|
522
|
+
case ENUM.CHANGE_TYPE.RESULT_ADD_AFTER:
|
|
523
|
+
isArray(value) ? modifyValue = modifyValue.concat(value) : modifyValue.push(value);
|
|
524
|
+
break;
|
|
525
|
+
case ENUM.CHANGE_TYPE.RESULT_ADD_BEFORE:
|
|
526
|
+
isArray(value) ? modifyValue = value.concat(modifyValue) : modifyValue.unshift(value);
|
|
527
|
+
break;
|
|
528
|
+
case ENUM.CHANGE_TYPE.RESULT_REMOVE_BY_ID:
|
|
529
|
+
if (matchedIndex >= 0) {
|
|
530
|
+
modifyValue.splice(matchedIndex, 1);
|
|
531
|
+
} else if (isArray(_id)) {
|
|
532
|
+
modifyValue = modifyValue.filter((_) => _id.indexOf(_[_uniqueKey]) === -1);
|
|
533
|
+
}
|
|
534
|
+
break;
|
|
535
|
+
case ENUM.CHANGE_TYPE.RESULT_INSERT_TO_BEFORE:
|
|
536
|
+
if (matchedIndex >= 0) {
|
|
537
|
+
modifyValue.splice(matchedIndex, 0, value);
|
|
538
|
+
}
|
|
539
|
+
break;
|
|
540
|
+
case ENUM.CHANGE_TYPE.RESULT_INSERT_TO_AFTER:
|
|
541
|
+
if (matchedIndex >= 0) {
|
|
542
|
+
modifyValue.splice(matchedIndex + 1, 0, value);
|
|
543
|
+
}
|
|
544
|
+
break;
|
|
545
|
+
case ENUM.CHANGE_TYPE.RESULT_LIST_MERGE:
|
|
546
|
+
combineArrayData(modifyValue, value, _uniqueKey);
|
|
547
|
+
break;
|
|
548
|
+
}
|
|
549
|
+
fieldData[_changeKey] = modifyValue;
|
|
550
|
+
}
|
|
551
|
+
const afterLength = computeResultLength(fieldData[ENUM.FIELD_DATA.RESULT_KEY]);
|
|
552
|
+
fieldData.total = fieldData.total + afterLength - beforeLength;
|
|
553
|
+
fieldData.nothing = afterLength === 0;
|
|
554
|
+
setter({
|
|
555
|
+
key: fieldName,
|
|
556
|
+
type: ENUM.SETTER_TYPE.MERGE,
|
|
557
|
+
value: fieldData,
|
|
558
|
+
callback: () => {
|
|
559
|
+
resolve(null);
|
|
560
|
+
}
|
|
561
|
+
});
|
|
562
|
+
});
|
|
563
|
+
};
|
|
564
|
+
export { ENUM, initData, initState, loadMore, updateState, utils };
|
package/dist/js-core.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var z=Object.defineProperty,J=Object.defineProperties;var W=Object.getOwnPropertyDescriptors;var k=Object.getOwnPropertySymbols;var Z=Object.prototype.hasOwnProperty,v=Object.prototype.propertyIsEnumerable;var x=(l,o,E)=>o in l?z(l,o,{enumerable:!0,configurable:!0,writable:!0,value:E}):l[o]=E,I=(l,o)=>{for(var E in o||(o={}))Z.call(o,E)&&x(l,E,o[E]);if(k)for(var E of k(o))v.call(o,E)&&x(l,E,o[E]);return l},b=(l,o)=>J(l,W(o));(function(l,o){typeof exports=="object"&&typeof module!="undefined"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(l=typeof globalThis!="undefined"?globalThis:l||self,o(l.JsCore={}))})(this,function(l){"use strict";const o=["jump","sinceId","page","seenIds","auto"];var E={SETTER_TYPE:{RESET:0,MERGE:1},FETCH_TYPE_ARRAY:o,FETCH_TYPE:{PAGINATION:o[0],SINCE_FIRST_OR_END_ID:o[1],SCROLL_LOAD_MORE:o[2],HAS_LOADED_IDS:o[3],AUTO:o[4]},CHANGE_TYPE:{SEARCH_FIELD:"search",RESET_FIELD:"reset",RESULT_UPDATE_KV:"update",RESULT_ADD_AFTER:"push",RESULT_ADD_BEFORE:"unshift",RESULT_REMOVE_BY_ID:"delete",RESULT_INSERT_TO_BEFORE:"insert-before",RESULT_INSERT_TO_AFTER:"insert-after",RESULT_LIST_MERGE:"patch",RESULT_ITEM_MERGE:"merge"},FIELD_DATA:{RESULT_KEY:"result",EXTRA_KEY:"extra"},DEFAULT_UNIQUE_KEY_NAME:"id"};const N=(e={})=>I({result:[],noMore:!1,nothing:!1,loading:!1,error:null,extra:null,fetched:!1,page:0,total:0},e),h=({func:e,type:n,query:t={}})=>{e=typeof e=="string"?e:`api-${Math.random().toString(36).substring(2)}`,n=n||"auto";let s=`${e}-${n}`;return Object.keys(t).filter(_=>!~["undefined","object","function"].indexOf(typeof t[_])&&!~["page","is_up","since_id","seen_ids","__refresh__","__reload__"].indexOf(_)).sort().forEach(_=>{s+=`-${_}-${t[_]}`}),s},L=(e,n)=>{if(!n)return e||"";let t=e||"";return(p(n)?n:n.split(".")).forEach(_=>{t=t[_]}),t||""},m=(e,n,t)=>{if(/\./.test(n)){const s=n.split("."),_=s.pop();let a=e;s.forEach(i=>{a=a[i]}),a[_]=t}else e[n]=t},G=(e,n,t)=>{if(p(e)){const s=O(n,e,t);return s<0?void 0:e[s]}return e[n]},O=(e,n,t)=>{let s=-1;for(let _=0;_<n.length;_++)if(L(n[_],t.toString()).toString()===(e||"").toString()){s=_;break}return s},j=(e,n,t)=>{p(n)?n.forEach(s=>{const _=L(s,t).toString();e.forEach((a,i)=>{L(a,t).toString()===_&&(e[i]=I(I({},a),s))})}):Object.keys(n).forEach(s=>{const _=(s||"").toString();e.forEach((a,i)=>{L(a,t).toString()===_&&(e[i]=I(I({},a),n[s]))})})},p=e=>Object.prototype.toString.call(e)==="[object Array]",H=(e,n,t,s,_)=>{if(s===E.FETCH_TYPE.PAGINATION){e[n]=t;return}if(p(t)){e[n]=_?t.concat(e[n]||[]):(e[n]||[]).concat(t);return}if(n!==E.FIELD_DATA.RESULT_KEY){e[n]=t;return}p(e[n])&&(e[n]={}),Object.keys(t).forEach(a=>{e[n][a]=e[n][a]?_?t[a].concat(e[n][a]):e[n][a].concat(t[a]):t[a]})},U=e=>{let n=0;return p(e)?n=e.length:Object.keys(e).forEach(t=>{n+=e[t].length}),n},M=({field:e,uniqueKey:n,query:t,type:s})=>{const _={};if(t=t||{},e.fetched){const a=n||E.DEFAULT_UNIQUE_KEY_NAME;s===E.FETCH_TYPE.AUTO?(_.seen_ids=e.result.map(i=>L(i,a)).join(","),_.since_id=L(e.result[t.is_up?0:e.result.length-1],a),_.is_up=t.is_up?1:0,_.page=t.page||e.page+1):s===E.FETCH_TYPE.HAS_LOADED_IDS?_.seen_ids=e.result.map(i=>L(i,a)).join(","):s===E.FETCH_TYPE.SINCE_FIRST_OR_END_ID?(_.since_id=L(e.result[t.is_up?0:e.result.length-1],a),_.is_up=t.is_up?1:0):s===E.FETCH_TYPE.PAGINATION?_.page=t.page:s===E.FETCH_TYPE.SCROLL_LOAD_MORE&&(_.page=e.page+1)}else s===E.FETCH_TYPE.AUTO?(_.seen_ids="",_.since_id=t.sinceId||(t.is_up?999999999:0),_.is_up=t.is_up?1:0,_.page=t.page||e.page||1):s===E.FETCH_TYPE.HAS_LOADED_IDS?_.seen_ids="":s===E.FETCH_TYPE.SINCE_FIRST_OR_END_ID?(_.since_id=t.sinceId||(t.is_up?999999999:0),_.is_up=t.is_up?1:0):s===E.FETCH_TYPE.PAGINATION?_.page=t.page||e.page:s===E.FETCH_TYPE.SCROLL_LOAD_MORE&&(_.page=1);return I(I({},t),_)};var B=Object.freeze(Object.defineProperty({__proto__:null,generateDefaultField:N,generateFieldName:h,getObjectDeepValue:L,updateObjectDeepValue:m,searchValueByKey:G,computeMatchedItemIndex:O,combineArrayData:j,isArray:p,setReactivityField:H,computeResultLength:U,generateRequestParams:M},Symbol.toStringTag,{value:"Module"}));const K=({getter:e,setter:n,data:t,fieldName:s,type:_,page:a,insertBefore:i})=>new Promise((u,S)=>{const T=e(s);if(!T){S();return}const{result:D,extra:A}=t,f=U(D)===0;T.nothing=T.fetched?!1:f,T.fetched=!0,T.total=t.total||0,_===E.FETCH_TYPE.PAGINATION?(T.noMore=!1,T.page=+a):(T.noMore=t.no_more||f,T.page=T.page+1),T.loading=!1,H(T,E.FIELD_DATA.RESULT_KEY,D,_,i),A&&H(T,E.FIELD_DATA.EXTRA_KEY,A,_,i),n({key:s,type:E.SETTER_TYPE.RESET,value:T,callback:()=>{u(null)}})}),V=({setter:e,fieldName:n,error:t})=>{e({key:n,type:E.SETTER_TYPE.MERGE,value:{error:t,loading:!1}})},w=({getter:e,setter:n,func:t,type:s,query:_={},opts:a={}})=>new Promise(i=>{const u=h({func:t,type:s,query:_});if(e(u)){i(null);return}n({key:u,type:E.SETTER_TYPE.RESET,value:N(a),callback:()=>{i(null)}})}),X=({getter:e,setter:n,func:t,type:s,query:_={},api:a,uniqueKey:i,callback:u})=>new Promise((S,T)=>{const D=h({func:t,type:s,query:_}),A=e(D),f=!!_.__refresh__,c=!!_.__reload__;if(A&&A.error&&!f||A&&A.loading)return S(null);const R=A&&A.fetched&&!f;if(R)return S(null);const g=M({field:b(I({},A),{fetched:!1}),uniqueKey:i,query:_,type:s}),F=()=>{(()=>new Promise(Y=>{(()=>{(typeof t=="string"?a[t]:t)(g).then(Y).catch(C=>{V({setter:n,fieldName:D,error:C}),T(C)})})()}))().then(Y=>{const r=()=>{K({getter:e,setter:n,data:Y,fieldName:D,type:s,page:g.page||0,insertBefore:!1}).then(()=>{u&&u({params:g,data:Y,refresh:f}),S(null)})};c?n({key:D,type:E.SETTER_TYPE.RESET,value:N(),callback:r}):r()})};!R&&!c?n({key:D,type:E.SETTER_TYPE.RESET,value:b(I({},N()),{loading:!0,error:null}),callback:F}):F()}),$=({getter:e,setter:n,query:t={},type:s,func:_,api:a,uniqueKey:i,errorRetry:u,callback:S})=>new Promise((T,D)=>{const A=h({func:_,type:s,query:t}),f=e(A);if(!f||f.loading||f.nothing||f.noMore&&!u||s===E.FETCH_TYPE.PAGINATION&&+t.page===f.page)return T(null);let c;s===E.FETCH_TYPE.PAGINATION?c={loading:!0,error:null,[E.FIELD_DATA.RESULT_KEY]:[],[E.FIELD_DATA.EXTRA_KEY]:null}:c={loading:!0,error:null};const R=M({field:f,uniqueKey:i,query:t,type:s});R[E.FIELD_DATA.EXTRA_KEY]=f[E.FIELD_DATA.EXTRA_KEY];const g=()=>{(typeof _=="string"?a[_]:_)(R).then(d=>{K({getter:e,setter:n,data:d,fieldName:A,type:s,page:R.page||0,insertBefore:!!t.is_up}).then(()=>{S&&S({params:R,data:d,refresh:!1}),T(null)})}).catch(d=>{V({setter:n,fieldName:A,error:d}),D(d)})};n({key:A,type:E.SETTER_TYPE.MERGE,value:c,callback:g})}),Q=({getter:e,setter:n,type:t,func:s,query:_={},method:a,value:i,id:u,uniqueKey:S,changeKey:T})=>new Promise((D,A)=>{const f=h({func:s,type:t,query:_}),c=e(f);if(!c){A();return}const R=u||"",g=S||E.DEFAULT_UNIQUE_KEY_NAME,F=T||E.FIELD_DATA.RESULT_KEY,d=U(c[E.FIELD_DATA.RESULT_KEY]);if(a===E.CHANGE_TYPE.SEARCH_FIELD)D(G(c[E.FIELD_DATA.RESULT_KEY],R,g));else if(a===E.CHANGE_TYPE.RESULT_UPDATE_KV){const r=O(R,c[E.FIELD_DATA.RESULT_KEY],g);m(c[E.FIELD_DATA.RESULT_KEY][r],F,i)}else if(a===E.CHANGE_TYPE.RESULT_ITEM_MERGE){const r=O(R,c[E.FIELD_DATA.RESULT_KEY],g);c[E.FIELD_DATA.RESULT_KEY][r]=I(I({},c[E.FIELD_DATA.RESULT_KEY][r]),i)}else if(a===E.CHANGE_TYPE.RESET_FIELD)m(c,F,i);else{let r=L(c,F);const P=O(R,r,g);switch(a){case E.CHANGE_TYPE.RESULT_ADD_AFTER:p(i)?r=r.concat(i):r.push(i);break;case E.CHANGE_TYPE.RESULT_ADD_BEFORE:p(i)?r=i.concat(r):r.unshift(i);break;case E.CHANGE_TYPE.RESULT_REMOVE_BY_ID:P>=0?r.splice(P,1):p(R)&&(r=r.filter(C=>R.indexOf(C[g])===-1));break;case E.CHANGE_TYPE.RESULT_INSERT_TO_BEFORE:P>=0&&r.splice(P,0,i);break;case E.CHANGE_TYPE.RESULT_INSERT_TO_AFTER:P>=0&&r.splice(P+1,0,i);break;case E.CHANGE_TYPE.RESULT_LIST_MERGE:j(r,i,g);break}c[F]=r}const Y=U(c[E.FIELD_DATA.RESULT_KEY]);c.total=c.total+Y-d,c.nothing=Y===0,n({key:f,type:E.SETTER_TYPE.MERGE,value:c,callback:()=>{D(null)}})});l.ENUM=E,l.initData=X,l.initState=w,l.loadMore=$,l.updateState=Q,l.utils=B,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowlist/js-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"main": "dist/js-core.umd.js",
|
|
5
5
|
"module": "dist/js-core.es.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -31,25 +31,26 @@
|
|
|
31
31
|
"lint": "eslint --ext js,jsx,ts,tsx,vue . --fix"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@typescript-eslint/eslint-plugin": "^4.18.0",
|
|
35
|
-
"@typescript-eslint/parser": "^4.18.0",
|
|
36
|
-
"@vue/eslint-config-prettier": "^6.0.0",
|
|
37
|
-
"@vue/eslint-config-typescript": "^7.0.0",
|
|
38
|
-
"eslint": "^6.7.2",
|
|
39
|
-
"eslint-plugin-prettier": "^3.3.1",
|
|
40
|
-
"eslint-plugin-vue": "^7.0.0",
|
|
41
34
|
"@babel/preset-env": "^7.14.7",
|
|
42
35
|
"@babel/preset-typescript": "^7.14.5",
|
|
43
|
-
"@
|
|
44
|
-
"@
|
|
45
|
-
"@
|
|
46
|
-
"@
|
|
47
|
-
"
|
|
36
|
+
"@faker-js/faker": "^6.1.2",
|
|
37
|
+
"@types/jest": "^27.4.1",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^5.19.0",
|
|
39
|
+
"@typescript-eslint/parser": "^5.19.0",
|
|
40
|
+
"@vue/cli-plugin-unit-jest": "~5.0.4",
|
|
41
|
+
"@vue/cli-service": "~5.0.4",
|
|
42
|
+
"@vue/eslint-config-prettier": "^7.0.0",
|
|
43
|
+
"@vue/eslint-config-typescript": "^10.0.0",
|
|
44
|
+
"@vue/test-utils": "^2.0.0-rc.19",
|
|
45
|
+
"eslint": "^8.13.0",
|
|
46
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
47
|
+
"eslint-plugin-vue": "^8.6.0",
|
|
48
48
|
"jest-localstorage-mock": "^2.4.8",
|
|
49
|
-
"ts-babel": "^6.1.7",
|
|
50
49
|
"prettier": "^2.3.2",
|
|
51
|
-
"
|
|
50
|
+
"ts-babel": "^6.1.7",
|
|
51
|
+
"ts-jest": "^27.1.4",
|
|
52
|
+
"typescript": "^4.6.3",
|
|
52
53
|
"vite": "^2.3.8",
|
|
53
|
-
"vite-plugin-dts": "^0.5
|
|
54
|
+
"vite-plugin-dts": "^1.0.5"
|
|
54
55
|
}
|
|
55
56
|
}
|
package/src/actions.ts
CHANGED
|
@@ -50,12 +50,10 @@ export const initState = ({
|
|
|
50
50
|
export const initData = ({
|
|
51
51
|
getter,
|
|
52
52
|
setter,
|
|
53
|
-
cache,
|
|
54
53
|
func,
|
|
55
54
|
type,
|
|
56
55
|
query = {},
|
|
57
56
|
api,
|
|
58
|
-
cacheTimeout,
|
|
59
57
|
uniqueKey,
|
|
60
58
|
callback
|
|
61
59
|
}: initDataType): Promise<any> =>
|
|
@@ -87,7 +85,6 @@ export const initData = ({
|
|
|
87
85
|
query,
|
|
88
86
|
type
|
|
89
87
|
})
|
|
90
|
-
let fromLocal = false
|
|
91
88
|
|
|
92
89
|
const getData = () => {
|
|
93
90
|
const loadData = () =>
|
|
@@ -103,19 +100,7 @@ export const initData = ({
|
|
|
103
100
|
})
|
|
104
101
|
}
|
|
105
102
|
|
|
106
|
-
|
|
107
|
-
cache
|
|
108
|
-
.get({ key: fieldName })
|
|
109
|
-
.then((data) => {
|
|
110
|
-
fromLocal = true
|
|
111
|
-
res(data)
|
|
112
|
-
})
|
|
113
|
-
.catch(() => {
|
|
114
|
-
getDataFromAPI()
|
|
115
|
-
})
|
|
116
|
-
} else {
|
|
117
|
-
getDataFromAPI()
|
|
118
|
-
}
|
|
103
|
+
getDataFromAPI()
|
|
119
104
|
})
|
|
120
105
|
|
|
121
106
|
loadData().then((data) => {
|
|
@@ -123,12 +108,9 @@ export const initData = ({
|
|
|
123
108
|
SET_DATA({
|
|
124
109
|
getter,
|
|
125
110
|
setter,
|
|
126
|
-
cache,
|
|
127
111
|
data,
|
|
128
112
|
fieldName,
|
|
129
113
|
type,
|
|
130
|
-
fromLocal,
|
|
131
|
-
cacheTimeout,
|
|
132
114
|
page: params.page || 0,
|
|
133
115
|
insertBefore: false
|
|
134
116
|
}).then(() => {
|
|
@@ -177,12 +159,10 @@ export const initData = ({
|
|
|
177
159
|
export const loadMore = ({
|
|
178
160
|
getter,
|
|
179
161
|
setter,
|
|
180
|
-
cache,
|
|
181
162
|
query = {},
|
|
182
163
|
type,
|
|
183
164
|
func,
|
|
184
165
|
api,
|
|
185
|
-
cacheTimeout,
|
|
186
166
|
uniqueKey,
|
|
187
167
|
errorRetry,
|
|
188
168
|
callback
|
|
@@ -245,12 +225,9 @@ export const loadMore = ({
|
|
|
245
225
|
SET_DATA({
|
|
246
226
|
getter,
|
|
247
227
|
setter,
|
|
248
|
-
cache,
|
|
249
228
|
data,
|
|
250
229
|
fieldName,
|
|
251
230
|
type,
|
|
252
|
-
fromLocal: false,
|
|
253
|
-
cacheTimeout,
|
|
254
231
|
page: params.page || 0,
|
|
255
232
|
insertBefore: !!query.is_up
|
|
256
233
|
}).then(() => {
|
|
@@ -281,7 +258,6 @@ export const loadMore = ({
|
|
|
281
258
|
export const updateState = ({
|
|
282
259
|
getter,
|
|
283
260
|
setter,
|
|
284
|
-
cache,
|
|
285
261
|
type,
|
|
286
262
|
func,
|
|
287
263
|
query = {},
|
|
@@ -289,8 +265,7 @@ export const updateState = ({
|
|
|
289
265
|
value,
|
|
290
266
|
id,
|
|
291
267
|
uniqueKey,
|
|
292
|
-
changeKey
|
|
293
|
-
cacheTimeout
|
|
268
|
+
changeKey
|
|
294
269
|
}: updateStateType) => {
|
|
295
270
|
return new Promise((resolve, reject) => {
|
|
296
271
|
const fieldName = generateFieldName({ func, type, query })
|
|
@@ -397,18 +372,6 @@ export const updateState = ({
|
|
|
397
372
|
type: ENUM.SETTER_TYPE.MERGE,
|
|
398
373
|
value: fieldData,
|
|
399
374
|
callback: () => {
|
|
400
|
-
if (cacheTimeout && cache) {
|
|
401
|
-
cache
|
|
402
|
-
.set({
|
|
403
|
-
key: fieldName,
|
|
404
|
-
value: fieldData,
|
|
405
|
-
timeout: cacheTimeout
|
|
406
|
-
})
|
|
407
|
-
.then(resolve)
|
|
408
|
-
.catch(resolve)
|
|
409
|
-
return
|
|
410
|
-
}
|
|
411
|
-
|
|
412
375
|
resolve(null)
|
|
413
376
|
}
|
|
414
377
|
})
|
package/src/setters.ts
CHANGED
|
@@ -5,28 +5,13 @@ import type { setDataType, setErrorType } from './types'
|
|
|
5
5
|
export const SET_DATA = ({
|
|
6
6
|
getter,
|
|
7
7
|
setter,
|
|
8
|
-
cache,
|
|
9
8
|
data,
|
|
10
9
|
fieldName,
|
|
11
10
|
type,
|
|
12
|
-
fromLocal,
|
|
13
|
-
cacheTimeout,
|
|
14
11
|
page,
|
|
15
12
|
insertBefore
|
|
16
13
|
}: setDataType): Promise<any> => {
|
|
17
14
|
return new Promise((resolve, reject) => {
|
|
18
|
-
if (fromLocal) {
|
|
19
|
-
setter({
|
|
20
|
-
key: fieldName,
|
|
21
|
-
type: ENUM.SETTER_TYPE.RESET,
|
|
22
|
-
value: data,
|
|
23
|
-
callback: () => {
|
|
24
|
-
resolve(null)
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
return
|
|
28
|
-
}
|
|
29
|
-
|
|
30
15
|
const fieldData = getter(fieldName)
|
|
31
16
|
if (!fieldData) {
|
|
32
17
|
reject()
|
|
@@ -68,18 +53,6 @@ export const SET_DATA = ({
|
|
|
68
53
|
type: ENUM.SETTER_TYPE.RESET,
|
|
69
54
|
value: fieldData,
|
|
70
55
|
callback: () => {
|
|
71
|
-
if (cacheTimeout && cache && !fieldData.nothing) {
|
|
72
|
-
cache
|
|
73
|
-
.set({
|
|
74
|
-
key: fieldName,
|
|
75
|
-
value: fieldData,
|
|
76
|
-
timeout: cacheTimeout
|
|
77
|
-
})
|
|
78
|
-
.then(resolve)
|
|
79
|
-
.catch(resolve)
|
|
80
|
-
return
|
|
81
|
-
}
|
|
82
|
-
|
|
83
56
|
resolve(null)
|
|
84
57
|
}
|
|
85
58
|
})
|
package/src/types.ts
CHANGED
|
@@ -59,31 +59,16 @@ export type setterFuncParams = {
|
|
|
59
59
|
|
|
60
60
|
export type initStateType = {
|
|
61
61
|
getter: (str: string) => defaultField
|
|
62
|
-
setter: (obj: setterFuncParams) =>
|
|
62
|
+
setter: (obj: setterFuncParams) => void
|
|
63
63
|
func: string | (() => {})
|
|
64
64
|
type: fetchTypes
|
|
65
65
|
query?: keyMap
|
|
66
66
|
opts?: keyMap
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
export type cacheType = {
|
|
70
|
-
get: ({ key }: { key: string }) => Promise<any>
|
|
71
|
-
set: ({
|
|
72
|
-
key,
|
|
73
|
-
value,
|
|
74
|
-
timeout
|
|
75
|
-
}: {
|
|
76
|
-
key: string
|
|
77
|
-
value: any
|
|
78
|
-
timeout?: number
|
|
79
|
-
}) => Promise<any>
|
|
80
|
-
del: ({ key }: { key: string }) => void
|
|
81
|
-
}
|
|
82
|
-
|
|
83
69
|
export type initDataType = {
|
|
84
70
|
getter: (str: string) => defaultField
|
|
85
|
-
setter: (obj: setterFuncParams) =>
|
|
86
|
-
cache: cacheType
|
|
71
|
+
setter: (obj: setterFuncParams) => void
|
|
87
72
|
func: string | (() => {})
|
|
88
73
|
type: fetchTypes
|
|
89
74
|
query?: keyMap
|
|
@@ -95,8 +80,7 @@ export type initDataType = {
|
|
|
95
80
|
|
|
96
81
|
export type loadMoreType = {
|
|
97
82
|
getter: (str: string) => defaultField
|
|
98
|
-
setter: (obj: setterFuncParams) =>
|
|
99
|
-
cache: cacheType
|
|
83
|
+
setter: (obj: setterFuncParams) => void
|
|
100
84
|
func: string | (() => {})
|
|
101
85
|
type: fetchTypes
|
|
102
86
|
query?: keyMap
|
|
@@ -109,8 +93,7 @@ export type loadMoreType = {
|
|
|
109
93
|
|
|
110
94
|
export type updateStateType = {
|
|
111
95
|
getter: (str: string) => defaultField
|
|
112
|
-
setter: (obj: setterFuncParams) =>
|
|
113
|
-
cache: cacheType
|
|
96
|
+
setter: (obj: setterFuncParams) => void
|
|
114
97
|
func: string | (() => {})
|
|
115
98
|
type: fetchTypes
|
|
116
99
|
query?: keyMap
|
|
@@ -120,24 +103,20 @@ export type updateStateType = {
|
|
|
120
103
|
changeKey: string
|
|
121
104
|
cacheTimeout: number
|
|
122
105
|
uniqueKey: string
|
|
123
|
-
callback: (obj?: keyMap) => void
|
|
124
106
|
}
|
|
125
107
|
|
|
126
108
|
export type setDataType = {
|
|
127
109
|
getter: (str: string) => defaultField
|
|
128
|
-
setter: (obj: setterFuncParams) =>
|
|
129
|
-
cache: cacheType
|
|
110
|
+
setter: (obj: setterFuncParams) => void
|
|
130
111
|
data: any
|
|
131
112
|
fieldName: string
|
|
132
113
|
type: fetchTypes
|
|
133
|
-
fromLocal: boolean
|
|
134
|
-
cacheTimeout: number
|
|
135
114
|
page: number
|
|
136
115
|
insertBefore: boolean
|
|
137
116
|
}
|
|
138
117
|
|
|
139
118
|
export type setErrorType = {
|
|
140
|
-
setter: (obj: setterFuncParams) =>
|
|
119
|
+
setter: (obj: setterFuncParams) => void
|
|
141
120
|
fieldName: string
|
|
142
121
|
error: null | Error
|
|
143
122
|
}
|
package/src/utils.ts
CHANGED
|
@@ -27,7 +27,6 @@ export const generateDefaultField = (opts = {}): defaultField => ({
|
|
|
27
27
|
...opts
|
|
28
28
|
})
|
|
29
29
|
|
|
30
|
-
let seed = 0
|
|
31
30
|
/**
|
|
32
31
|
* 根据参数生成 field 的 namespace
|
|
33
32
|
* @param {string} func
|
|
@@ -40,7 +39,10 @@ export const generateFieldName = ({
|
|
|
40
39
|
type,
|
|
41
40
|
query = {}
|
|
42
41
|
}: generateFieldProps): string => {
|
|
43
|
-
func =
|
|
42
|
+
func =
|
|
43
|
+
typeof func === 'string'
|
|
44
|
+
? func
|
|
45
|
+
: `api-${Math.random().toString(36).substring(2)}`
|
|
44
46
|
type = type || 'auto'
|
|
45
47
|
let result = `${func}-${type}`
|
|
46
48
|
Object.keys(query)
|
package/dist/src/actions.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { initStateType, initDataType, loadMoreType, updateStateType } from './types';
|
|
2
|
-
export declare const initState: ({ getter, setter, func, type, query, opts }: initStateType) => Promise<null>;
|
|
3
|
-
export declare const initData: ({ getter, setter, cache, func, type, query, api, cacheTimeout, uniqueKey, callback }: initDataType) => Promise<any>;
|
|
4
|
-
export declare const loadMore: ({ getter, setter, cache, query, type, func, api, cacheTimeout, uniqueKey, errorRetry, callback }: loadMoreType) => Promise<any>;
|
|
5
|
-
export declare const updateState: ({ getter, setter, cache, type, func, query, method, value, id, uniqueKey, changeKey, cacheTimeout }: updateStateType) => Promise<unknown>;
|
package/dist/src/enum.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
declare const _default: {
|
|
2
|
-
SETTER_TYPE: {
|
|
3
|
-
RESET: number;
|
|
4
|
-
MERGE: number;
|
|
5
|
-
};
|
|
6
|
-
FETCH_TYPE_ARRAY: string[];
|
|
7
|
-
FETCH_TYPE: {
|
|
8
|
-
PAGINATION: string;
|
|
9
|
-
SINCE_FIRST_OR_END_ID: string;
|
|
10
|
-
SCROLL_LOAD_MORE: string;
|
|
11
|
-
HAS_LOADED_IDS: string;
|
|
12
|
-
AUTO: string;
|
|
13
|
-
};
|
|
14
|
-
CHANGE_TYPE: {
|
|
15
|
-
SEARCH_FIELD: string;
|
|
16
|
-
RESET_FIELD: string;
|
|
17
|
-
RESULT_UPDATE_KV: string;
|
|
18
|
-
RESULT_ADD_AFTER: string;
|
|
19
|
-
RESULT_ADD_BEFORE: string;
|
|
20
|
-
RESULT_REMOVE_BY_ID: string;
|
|
21
|
-
RESULT_INSERT_TO_BEFORE: string;
|
|
22
|
-
RESULT_INSERT_TO_AFTER: string;
|
|
23
|
-
RESULT_LIST_MERGE: string;
|
|
24
|
-
RESULT_ITEM_MERGE: string;
|
|
25
|
-
};
|
|
26
|
-
FIELD_DATA: {
|
|
27
|
-
RESULT_KEY: string;
|
|
28
|
-
EXTRA_KEY: string;
|
|
29
|
-
};
|
|
30
|
-
DEFAULT_UNIQUE_KEY_NAME: string;
|
|
31
|
-
};
|
|
32
|
-
export default _default;
|
package/dist/src/index.d.ts
DELETED
package/dist/src/setters.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { setDataType, setErrorType } from './types';
|
|
2
|
-
export declare const SET_DATA: ({ getter, setter, cache, data, fieldName, type, fromLocal, cacheTimeout, page, insertBefore }: setDataType) => Promise<any>;
|
|
3
|
-
export declare const SET_ERROR: ({ setter, fieldName, error }: setErrorType) => void;
|
package/dist/src/types.d.ts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
export declare type objectKey = string | number;
|
|
2
|
-
export declare type keyMap = Record<objectKey, any>;
|
|
3
|
-
export declare type morphArray = any[];
|
|
4
|
-
export declare type fieldResult = morphArray | keyMap;
|
|
5
|
-
export declare type defaultField = {
|
|
6
|
-
result: fieldResult;
|
|
7
|
-
noMore: boolean;
|
|
8
|
-
nothing: boolean;
|
|
9
|
-
loading: boolean;
|
|
10
|
-
error: null | Error;
|
|
11
|
-
extra: null | any;
|
|
12
|
-
fetched: boolean;
|
|
13
|
-
page: number;
|
|
14
|
-
total: number;
|
|
15
|
-
};
|
|
16
|
-
export declare type fetchTypes = 'jump' | 'sinceId' | 'page' | 'seenIds' | 'auto';
|
|
17
|
-
export declare type fieldKeys = 'result' | 'noMore' | 'nothing' | 'loading' | 'error' | 'extra' | 'page' | 'total';
|
|
18
|
-
export declare type generateFieldProps = {
|
|
19
|
-
func: string | (() => {});
|
|
20
|
-
type: fetchTypes;
|
|
21
|
-
query: keyMap;
|
|
22
|
-
};
|
|
23
|
-
export declare type generateParamsType = {
|
|
24
|
-
field: defaultField;
|
|
25
|
-
uniqueKey: string;
|
|
26
|
-
query: keyMap;
|
|
27
|
-
type: fetchTypes;
|
|
28
|
-
};
|
|
29
|
-
export declare type generateParamsResp = {
|
|
30
|
-
seen_ids?: string;
|
|
31
|
-
since_id?: objectKey;
|
|
32
|
-
is_up?: 0 | 1;
|
|
33
|
-
page?: number;
|
|
34
|
-
};
|
|
35
|
-
export declare type setterFuncParams = {
|
|
36
|
-
key: string;
|
|
37
|
-
type: number;
|
|
38
|
-
value: any;
|
|
39
|
-
callback?: (obj?: keyMap) => void;
|
|
40
|
-
};
|
|
41
|
-
export declare type initStateType = {
|
|
42
|
-
getter: (str: string) => defaultField;
|
|
43
|
-
setter: (obj: setterFuncParams) => {};
|
|
44
|
-
func: string | (() => {});
|
|
45
|
-
type: fetchTypes;
|
|
46
|
-
query?: keyMap;
|
|
47
|
-
opts?: keyMap;
|
|
48
|
-
};
|
|
49
|
-
export declare type cacheType = {
|
|
50
|
-
get: ({ key }: {
|
|
51
|
-
key: string;
|
|
52
|
-
}) => Promise<any>;
|
|
53
|
-
set: ({ key, value, timeout }: {
|
|
54
|
-
key: string;
|
|
55
|
-
value: any;
|
|
56
|
-
timeout?: number;
|
|
57
|
-
}) => Promise<any>;
|
|
58
|
-
del: ({ key }: {
|
|
59
|
-
key: string;
|
|
60
|
-
}) => void;
|
|
61
|
-
};
|
|
62
|
-
export declare type initDataType = {
|
|
63
|
-
getter: (str: string) => defaultField;
|
|
64
|
-
setter: (obj: setterFuncParams) => {};
|
|
65
|
-
cache: cacheType;
|
|
66
|
-
func: string | (() => {});
|
|
67
|
-
type: fetchTypes;
|
|
68
|
-
query?: keyMap;
|
|
69
|
-
api: keyMap;
|
|
70
|
-
cacheTimeout: number;
|
|
71
|
-
uniqueKey: string;
|
|
72
|
-
callback: (obj?: keyMap) => void;
|
|
73
|
-
};
|
|
74
|
-
export declare type loadMoreType = {
|
|
75
|
-
getter: (str: string) => defaultField;
|
|
76
|
-
setter: (obj: setterFuncParams) => {};
|
|
77
|
-
cache: cacheType;
|
|
78
|
-
func: string | (() => {});
|
|
79
|
-
type: fetchTypes;
|
|
80
|
-
query?: keyMap;
|
|
81
|
-
api: keyMap;
|
|
82
|
-
cacheTimeout: number;
|
|
83
|
-
uniqueKey: string;
|
|
84
|
-
errorRetry: boolean;
|
|
85
|
-
callback: (obj?: keyMap) => void;
|
|
86
|
-
};
|
|
87
|
-
export declare type updateStateType = {
|
|
88
|
-
getter: (str: string) => defaultField;
|
|
89
|
-
setter: (obj: setterFuncParams) => {};
|
|
90
|
-
cache: cacheType;
|
|
91
|
-
func: string | (() => {});
|
|
92
|
-
type: fetchTypes;
|
|
93
|
-
query?: keyMap;
|
|
94
|
-
method: string;
|
|
95
|
-
value: any;
|
|
96
|
-
id: string | number | objectKey[];
|
|
97
|
-
changeKey: string;
|
|
98
|
-
cacheTimeout: number;
|
|
99
|
-
uniqueKey: string;
|
|
100
|
-
callback: (obj?: keyMap) => void;
|
|
101
|
-
};
|
|
102
|
-
export declare type setDataType = {
|
|
103
|
-
getter: (str: string) => defaultField;
|
|
104
|
-
setter: (obj: setterFuncParams) => {};
|
|
105
|
-
cache: cacheType;
|
|
106
|
-
data: any;
|
|
107
|
-
fieldName: string;
|
|
108
|
-
type: fetchTypes;
|
|
109
|
-
fromLocal: boolean;
|
|
110
|
-
cacheTimeout: number;
|
|
111
|
-
page: number;
|
|
112
|
-
insertBefore: boolean;
|
|
113
|
-
};
|
|
114
|
-
export declare type setErrorType = {
|
|
115
|
-
setter: (obj: setterFuncParams) => {};
|
|
116
|
-
fieldName: string;
|
|
117
|
-
error: null | Error;
|
|
118
|
-
};
|
package/dist/src/utils.d.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type { objectKey, keyMap, morphArray, fieldResult, defaultField, fetchTypes, fieldKeys, generateFieldProps, generateParamsType, generateParamsResp } from './types';
|
|
2
|
-
export declare const generateDefaultField: (opts?: {}) => defaultField;
|
|
3
|
-
/**
|
|
4
|
-
* 根据参数生成 field 的 namespace
|
|
5
|
-
* @param {string} func
|
|
6
|
-
* @param {string} type
|
|
7
|
-
* @param {object} query
|
|
8
|
-
* @return {string}
|
|
9
|
-
*/
|
|
10
|
-
export declare const generateFieldName: ({ func, type, query }: generateFieldProps) => string;
|
|
11
|
-
/**
|
|
12
|
-
* 根据 key 从 object 里拿 value
|
|
13
|
-
* @param {object} field
|
|
14
|
-
* @param {string} keys
|
|
15
|
-
* @return {*}
|
|
16
|
-
*/
|
|
17
|
-
export declare const getObjectDeepValue: (field: keyMap, keys: string | string[]) => any;
|
|
18
|
-
export declare const updateObjectDeepValue: (field: keyMap, changeKey: string, value: any) => void;
|
|
19
|
-
export declare const searchValueByKey: (result: fieldResult, id: objectKey, key: objectKey) => any;
|
|
20
|
-
/**
|
|
21
|
-
* 通过 id 匹配返回数组中某个对象的 index
|
|
22
|
-
* @param {int|string} itemId
|
|
23
|
-
* @param {array} fieldArr
|
|
24
|
-
* @param {int|string} changingKey
|
|
25
|
-
* @return {number}
|
|
26
|
-
*/
|
|
27
|
-
export declare const computeMatchedItemIndex: (itemId: objectKey, fieldArr: morphArray, changingKey: objectKey) => number;
|
|
28
|
-
export declare const combineArrayData: (fieldArray: any[], value: fieldResult, changingKey: string) => void;
|
|
29
|
-
/**
|
|
30
|
-
* 判断参数是否为数组
|
|
31
|
-
* @param {object|array} data
|
|
32
|
-
* @return {boolean}
|
|
33
|
-
*/
|
|
34
|
-
export declare const isArray: (data: any) => boolean;
|
|
35
|
-
/**
|
|
36
|
-
* 设置一个响应式的数据到对象上
|
|
37
|
-
* @param {object} field
|
|
38
|
-
* @param {string} key
|
|
39
|
-
* @param {array|object} value
|
|
40
|
-
* @param {string} type
|
|
41
|
-
* @param {boolean} insertBefore
|
|
42
|
-
*/
|
|
43
|
-
export declare const setReactivityField: (field: defaultField, key: fieldKeys, value: any, type: fetchTypes, insertBefore: boolean) => void;
|
|
44
|
-
/**
|
|
45
|
-
* 计算一个数据列的长度
|
|
46
|
-
* @param {array|object} data
|
|
47
|
-
* @return {number}
|
|
48
|
-
*/
|
|
49
|
-
export declare const computeResultLength: (data: fieldResult) => number;
|
|
50
|
-
/**
|
|
51
|
-
* 拼接请求的参数
|
|
52
|
-
* @param {object} field
|
|
53
|
-
* @param {string} uniqueKey
|
|
54
|
-
* @param {object} query
|
|
55
|
-
* @param {string} type
|
|
56
|
-
* @return {object}
|
|
57
|
-
*/
|
|
58
|
-
export declare const generateRequestParams: ({ field, uniqueKey, query, type }: generateParamsType) => generateParamsResp;
|
package/dist/tests/unit/api.d.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
export declare const testArrData: () => {
|
|
2
|
-
result: {
|
|
3
|
-
id: number;
|
|
4
|
-
slug: string;
|
|
5
|
-
obj: {
|
|
6
|
-
key: string;
|
|
7
|
-
};
|
|
8
|
-
arr: {
|
|
9
|
-
id: number;
|
|
10
|
-
text: string;
|
|
11
|
-
}[];
|
|
12
|
-
}[];
|
|
13
|
-
no_more: boolean;
|
|
14
|
-
total: number;
|
|
15
|
-
};
|
|
16
|
-
export declare const testCommentData: () => {
|
|
17
|
-
result: {
|
|
18
|
-
parent_id: number;
|
|
19
|
-
content: string;
|
|
20
|
-
children: {
|
|
21
|
-
sub_id: number;
|
|
22
|
-
content: string;
|
|
23
|
-
}[];
|
|
24
|
-
}[];
|
|
25
|
-
};
|
|
26
|
-
export declare const testArrFunc: () => Promise<unknown>;
|
|
27
|
-
export declare const testError: () => Promise<unknown>;
|
|
28
|
-
export declare const getListByPage: ({ page, count }: {
|
|
29
|
-
page: any;
|
|
30
|
-
count: any;
|
|
31
|
-
}) => Promise<unknown>;
|
|
32
|
-
export declare const getObjectByPage: ({ page, count }: {
|
|
33
|
-
page: any;
|
|
34
|
-
count: any;
|
|
35
|
-
}) => Promise<unknown>;
|
|
36
|
-
export declare const getListBySinceId: ({ since_id, is_up, count }: {
|
|
37
|
-
since_id: any;
|
|
38
|
-
is_up: any;
|
|
39
|
-
count: any;
|
|
40
|
-
}) => Promise<unknown>;
|
|
41
|
-
export declare const getListByJump: ({ page, count }: {
|
|
42
|
-
page: any;
|
|
43
|
-
count: any;
|
|
44
|
-
}) => Promise<unknown>;
|
|
45
|
-
export declare const getListWithError: ({ page, count }: {
|
|
46
|
-
page: any;
|
|
47
|
-
count: any;
|
|
48
|
-
}) => Promise<unknown>;
|
|
49
|
-
export declare const getListByFirstLoading: ({ page, count }: {
|
|
50
|
-
page: any;
|
|
51
|
-
count: any;
|
|
52
|
-
}) => Promise<unknown>;
|
|
53
|
-
export declare const getListByFirstError: ({ page, count }: {
|
|
54
|
-
page: any;
|
|
55
|
-
count: any;
|
|
56
|
-
}) => Promise<unknown>;
|
|
57
|
-
export declare const getListByLastId: ({ last_id, count }: {
|
|
58
|
-
last_id: any;
|
|
59
|
-
count: any;
|
|
60
|
-
}) => Promise<unknown>;
|
|
61
|
-
export declare const getListBySeenIds: ({ seen_ids, count }: {
|
|
62
|
-
seen_ids: any;
|
|
63
|
-
count: any;
|
|
64
|
-
}) => Promise<unknown>;
|
|
65
|
-
export declare const getListByNothing: ({ page, count }: {
|
|
66
|
-
page: any;
|
|
67
|
-
count: any;
|
|
68
|
-
}) => Promise<unknown>;
|
package/dist/tests/unit/env.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export declare const getter: (fieldName: any) => any;
|
|
2
|
-
export declare const setter: ({ key, type, value, callback }: {
|
|
3
|
-
key: any;
|
|
4
|
-
type: any;
|
|
5
|
-
value: any;
|
|
6
|
-
callback: any;
|
|
7
|
-
}) => void;
|
|
8
|
-
export declare const cache: {
|
|
9
|
-
set({ key, value, timeout }: {
|
|
10
|
-
key: any;
|
|
11
|
-
value: any;
|
|
12
|
-
timeout: any;
|
|
13
|
-
}): Promise<unknown>;
|
|
14
|
-
get({ key }: {
|
|
15
|
-
key: any;
|
|
16
|
-
}): Promise<unknown>;
|
|
17
|
-
del({ key }: {
|
|
18
|
-
key: any;
|
|
19
|
-
}): void;
|
|
20
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
declare const _default: {
|
|
2
|
-
get(count: any): {
|
|
3
|
-
id: number;
|
|
4
|
-
style: {
|
|
5
|
-
color: string;
|
|
6
|
-
};
|
|
7
|
-
width: number;
|
|
8
|
-
height: number;
|
|
9
|
-
data: any;
|
|
10
|
-
like: boolean;
|
|
11
|
-
} | {
|
|
12
|
-
id: number;
|
|
13
|
-
style: {
|
|
14
|
-
color: string;
|
|
15
|
-
};
|
|
16
|
-
width: number;
|
|
17
|
-
height: number;
|
|
18
|
-
data: any;
|
|
19
|
-
like: boolean;
|
|
20
|
-
}[];
|
|
21
|
-
getRandomColor(): string;
|
|
22
|
-
};
|
|
23
|
-
export default _default;
|