@superutils/fetch 1.4.1 → 1.5.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/README.md +7 -7
- package/dist/browser/index.min.js +1124 -0
- package/dist/browser/index.min.js.map +1 -0
- package/dist/index.cjs +477 -0
- package/dist/index.d.cts +915 -0
- package/dist/index.d.ts +189 -183
- package/dist/index.js +97 -119
- package/package.json +15 -7
package/README.md
CHANGED
|
@@ -154,7 +154,7 @@ import fetch from '@superutils/fetch'
|
|
|
154
154
|
|
|
155
155
|
// Create a debounced search function with a 300ms delay.
|
|
156
156
|
const searchProducts = fetch.get.deferred({
|
|
157
|
-
|
|
157
|
+
delay: 300, // Debounce delay
|
|
158
158
|
resolveIgnored: 'WITH_UNDEFINED', // Ignored (aborted) promises will resolve with `undefined`
|
|
159
159
|
})
|
|
160
160
|
|
|
@@ -183,7 +183,7 @@ setTimeout(() => {
|
|
|
183
183
|
|
|
184
184
|
- **`throttle: true`**: Switches from debounce to throttle mode. The first request for "iphone" would
|
|
185
185
|
execute immediately. The second request for "iphone 12", made within the 300ms throttle window, would be ignored.
|
|
186
|
-
- **`
|
|
186
|
+
- **`delay: 0`**: Disables debouncing and throttling, enabling sequential/queue mode. Both requests ("iphone"
|
|
187
187
|
and "iphone 12") would execute, but one after the other, never simultaneously.
|
|
188
188
|
- **`resolveIgnored` (enum)**: Controls how the promise for an aborted request (like the first "iphone" call) resolves.
|
|
189
189
|
1. `ResolveIgnored.WITH_UNDEFINED` (used in the example): The promise for the aborted "iphone"
|
|
@@ -208,7 +208,7 @@ import fetch from '@superutils/fetch'
|
|
|
208
208
|
// The URL and a 3-second timeout are set as defaults, creating a reusable client.
|
|
209
209
|
const getRandomQuote = fetch.get.deferred(
|
|
210
210
|
{
|
|
211
|
-
|
|
211
|
+
delay: 300, // Throttle window
|
|
212
212
|
throttle: true,
|
|
213
213
|
// Ignored calls will resolve with the result of the last successful call.
|
|
214
214
|
resolveIgnored: 'WITH_LAST',
|
|
@@ -261,7 +261,7 @@ import PromisE from '@superutils/promise'
|
|
|
261
261
|
// Create a throttled function to auto-save product updates.
|
|
262
262
|
const saveProductThrottled = fetch.post.deferred(
|
|
263
263
|
{
|
|
264
|
-
|
|
264
|
+
delay: 1000, // Throttle window of 1 second
|
|
265
265
|
throttle: true,
|
|
266
266
|
trailing: true, // Ensures the very last update is always saved
|
|
267
267
|
onResult: product => console.log(`[Saved] Product: ${product.title}`),
|
|
@@ -299,7 +299,7 @@ let currentRefreshToken = ''
|
|
|
299
299
|
// It waits 300ms after the last call before executing.
|
|
300
300
|
const requestNewToken = fetch.post.deferred(
|
|
301
301
|
{
|
|
302
|
-
|
|
302
|
+
delay: 300, // debounce delay
|
|
303
303
|
onResult: ({ refreshToken = '' }) => {
|
|
304
304
|
console.log(
|
|
305
305
|
`Auth token successfully refreshed at ${new Date().toISOString()}`,
|
|
@@ -534,7 +534,7 @@ const apiClient = createClient(
|
|
|
534
534
|
},
|
|
535
535
|
{
|
|
536
536
|
// default defer options (can be overridden)
|
|
537
|
-
|
|
537
|
+
delay: 300,
|
|
538
538
|
retry: 2, // If request fails, retry up to two more times
|
|
539
539
|
},
|
|
540
540
|
)
|
|
@@ -586,7 +586,7 @@ postClient(
|
|
|
586
586
|
// create a deferred client using "postClient"
|
|
587
587
|
const updateProduct = postClient.deferred(
|
|
588
588
|
{
|
|
589
|
-
|
|
589
|
+
delay: 300, // debounce duration
|
|
590
590
|
onResult: console.log, // prints only successful results
|
|
591
591
|
},
|
|
592
592
|
'https://dummyjson.com/products/add',
|