@hyper-fetch/react 5.0.1 → 5.0.2
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.cjs.js +41 -28
- package/dist/index.cjs.js.map +2 -2
- package/dist/index.d.ts +7 -7
- package/dist/index.esm.js +41 -28
- package/dist/index.esm.js.map +2 -2
- package/package.json +2 -3
- package/src/helpers/use-tracked-state/use-tracked-state.types.ts +3 -2
- package/src/helpers/use-tracked-state/use-tracked-state.utils.ts +8 -4
- package/src/hooks/use-fetch/use-fetch.types.ts +2 -2
- package/src/hooks/use-submit/use-submit.types.ts +3 -9
- package/src/utils/deep-equal.utils.ts +39 -32
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _hyper_fetch_core from '@hyper-fetch/core';
|
|
2
|
-
import { RequestInstance, Dispatcher, LoggerType, CacheValueType, ExtractResponseType, ExtractErrorType, ResponseDetailsType, ExtractAdapterReturnType, RequestEventType, ProgressType,
|
|
2
|
+
import { RequestInstance, Dispatcher, LoggerType, CacheValueType, ExtractResponseType, ExtractErrorType, ResponseDetailsType, ExtractAdapterReturnType, RequestEventType, ProgressType, NullableType, ExtractAdapterStatusType, ExtractAdapterType, ExtractAdapterExtraType, RequiredKeys, RequestSendType, QueueElementType, ClientInstance } from '@hyper-fetch/core';
|
|
3
3
|
import * as _hyper_fetch_sockets from '@hyper-fetch/sockets';
|
|
4
4
|
import { SocketInstance, ListenerInstance, ExtractListenerResponseType, ExtractSocketExtraType, ExtractListenerAdapterType, EmitterInstance } from '@hyper-fetch/sockets';
|
|
5
5
|
import React from 'react';
|
|
@@ -124,7 +124,7 @@ declare const getBounceData: (bounceData: {
|
|
|
124
124
|
type UseTrackedStateProps<T extends RequestInstance> = {
|
|
125
125
|
request: T;
|
|
126
126
|
logger: LoggerType;
|
|
127
|
-
initialData:
|
|
127
|
+
initialData: NullableType<Partial<ExtractAdapterReturnType<T>>>;
|
|
128
128
|
dispatcher: Dispatcher;
|
|
129
129
|
dependencyTracking: boolean;
|
|
130
130
|
defaultCacheEmitting?: boolean;
|
|
@@ -222,9 +222,9 @@ declare const useTrackedState: <T extends RequestInstance>({ request, dispatcher
|
|
|
222
222
|
|
|
223
223
|
declare const getDetailsState: (state?: UseTrackedStateType<RequestInstance>, details?: Partial<ResponseDetailsType>) => ResponseDetailsType;
|
|
224
224
|
declare const isStaleCacheData: (cacheTime: number, cacheTimestamp: NullableType<Date | number>) => boolean;
|
|
225
|
-
declare const getValidCacheData: <T extends RequestInstance>(request: T, initialData: ExtractAdapterReturnType<T
|
|
225
|
+
declare const getValidCacheData: <T extends RequestInstance>(request: T, initialData: Partial<ExtractAdapterReturnType<T>>, cacheData: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>, _hyper_fetch_core.AdapterInstance>) => CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>, _hyper_fetch_core.AdapterInstance>;
|
|
226
226
|
declare const getTimestamp: (timestamp?: NullableType<number | Date>) => Date;
|
|
227
|
-
declare const getInitialState: <T extends RequestInstance>(initialData:
|
|
227
|
+
declare const getInitialState: <T extends RequestInstance>(initialData: Partial<ExtractAdapterReturnType<T>>, dispatcher: Dispatcher, request: T) => UseTrackedStateType<T>;
|
|
228
228
|
|
|
229
229
|
declare const useSocketState: <DataType>(socket: SocketInstance, { dependencyTracking }: UseSocketStateProps) => readonly [UseSocketStateType<DataType>, {
|
|
230
230
|
setData: (data: DataType) => void;
|
|
@@ -276,7 +276,7 @@ type UseFetchOptionsType<T extends RequestInstance> = {
|
|
|
276
276
|
/**
|
|
277
277
|
* If cache is empty we can use placeholder data.
|
|
278
278
|
*/
|
|
279
|
-
initialData?:
|
|
279
|
+
initialData?: NullableType<Partial<ExtractAdapterReturnType<T>>>;
|
|
280
280
|
/**
|
|
281
281
|
* Enable/disable refresh data
|
|
282
282
|
*/
|
|
@@ -369,13 +369,13 @@ declare const useSubmit: <RequestType extends RequestInstance>(request: RequestT
|
|
|
369
369
|
|
|
370
370
|
type UseSubmitOptionsType<T extends RequestInstance> = {
|
|
371
371
|
/**
|
|
372
|
-
* Disable
|
|
372
|
+
* Disable submitting
|
|
373
373
|
*/
|
|
374
374
|
disabled?: boolean;
|
|
375
375
|
/**
|
|
376
376
|
* If cache is empty we can use placeholder data.
|
|
377
377
|
*/
|
|
378
|
-
initialData?:
|
|
378
|
+
initialData?: NullableType<Partial<ExtractAdapterReturnType<T>>>;
|
|
379
379
|
/**
|
|
380
380
|
* Enable/disable debouncing for often changing keys or refreshing, to limit requests to server.
|
|
381
381
|
*/
|
package/dist/index.esm.js
CHANGED
|
@@ -269,36 +269,43 @@ var isEmpty = (value) => {
|
|
|
269
269
|
return false;
|
|
270
270
|
};
|
|
271
271
|
var isEqual = (firstValue, secondValue) => {
|
|
272
|
-
|
|
273
|
-
const secondValueType = Object.prototype.toString.call(secondValue);
|
|
274
|
-
const firstType = typeof firstValue;
|
|
275
|
-
const secondType = typeof secondValue;
|
|
276
|
-
const isType = (type) => firstType === type && secondType === type;
|
|
277
|
-
const isTypeValue = (type) => firstValueType === type && secondValueType === type;
|
|
278
|
-
if (firstValueType !== secondValueType)
|
|
279
|
-
return false;
|
|
280
|
-
if (firstValue === null && secondValue === null)
|
|
281
|
-
return true;
|
|
282
|
-
if (isType("number") && Number.isNaN(firstValue) && Number.isNaN(secondValue))
|
|
283
|
-
return true;
|
|
284
|
-
if (isEmpty(firstValue) && isEmpty(secondValue))
|
|
272
|
+
if (firstValue === secondValue)
|
|
285
273
|
return true;
|
|
286
|
-
|
|
287
|
-
|
|
274
|
+
try {
|
|
275
|
+
const firstValueType = Object.prototype.toString.call(firstValue);
|
|
276
|
+
const secondValueType = Object.prototype.toString.call(secondValue);
|
|
277
|
+
const firstType = typeof firstValue;
|
|
278
|
+
const secondType = typeof secondValue;
|
|
279
|
+
const isType = (type) => firstType === type && secondType === type;
|
|
280
|
+
const isTypeValue = (type) => firstValueType === type && secondValueType === type;
|
|
281
|
+
if (firstValueType !== secondValueType)
|
|
288
282
|
return false;
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
283
|
+
if (firstValue === null && secondValue === null)
|
|
284
|
+
return true;
|
|
285
|
+
if (isType("number") && Number.isNaN(firstValue) && Number.isNaN(secondValue))
|
|
286
|
+
return true;
|
|
287
|
+
if (isEmpty(firstValue) && isEmpty(secondValue))
|
|
288
|
+
return true;
|
|
289
|
+
if (Array.isArray(firstValue) && Array.isArray(secondValue)) {
|
|
290
|
+
if (firstValue.length !== secondValue.length)
|
|
291
|
+
return false;
|
|
292
|
+
return !firstValue.some((element, i) => !isEqual(element, secondValue[i]));
|
|
293
|
+
}
|
|
294
|
+
if (isType("object") && isTypeValue("[object Object]")) {
|
|
295
|
+
if (Object.keys(firstValue).length !== Object.keys(secondValue).length)
|
|
296
|
+
return false;
|
|
297
|
+
return !Object.entries(firstValue).some(
|
|
298
|
+
([key, value]) => !isEqual(value, secondValue[key])
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
if (firstValue instanceof Date && secondValue instanceof Date) {
|
|
302
|
+
return +firstValue === +secondValue;
|
|
303
|
+
}
|
|
304
|
+
return firstValue === secondValue;
|
|
305
|
+
} catch (err) {
|
|
306
|
+
console.error(err);
|
|
307
|
+
return false;
|
|
300
308
|
}
|
|
301
|
-
return firstValue === secondValue;
|
|
302
309
|
};
|
|
303
310
|
|
|
304
311
|
// src/utils/bounce.utils.ts
|
|
@@ -326,7 +333,13 @@ var getValidCacheData = (request, initialData, cacheData) => {
|
|
|
326
333
|
return cacheData;
|
|
327
334
|
}
|
|
328
335
|
if (initialData) {
|
|
329
|
-
return __spreadProps(__spreadValues(__spreadValues({
|
|
336
|
+
return __spreadProps(__spreadValues(__spreadValues({
|
|
337
|
+
data: null,
|
|
338
|
+
error: null,
|
|
339
|
+
status: null,
|
|
340
|
+
success: null,
|
|
341
|
+
extra: null
|
|
342
|
+
}, initialData || {}), getDetailsState()), {
|
|
330
343
|
cacheTime: 1e3,
|
|
331
344
|
clearKey: request.client.cache.clearKey,
|
|
332
345
|
garbageCollection: request.garbageCollection
|