@ametie/vue-muza-use 0.3.0 → 0.3.1
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 +33 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -200,6 +200,38 @@ useApiPost('/user/settings', {
|
|
|
200
200
|
})
|
|
201
201
|
```
|
|
202
202
|
|
|
203
|
+
### ⏰ Auto-Polling (Interval)
|
|
204
|
+
Keep your data fresh with built-in polling support. It works smartly: by default, it **pauses** when the tab is hidden and **resumes immediately** when the user returns.
|
|
205
|
+
|
|
206
|
+
#### Simple Polling
|
|
207
|
+
Fetch data every 5 seconds.
|
|
208
|
+
```typescript
|
|
209
|
+
const { data } = useApi('/notifications', {
|
|
210
|
+
poll: 5000 // Simple number: interval in ms
|
|
211
|
+
})
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
#### Smart Control
|
|
215
|
+
Configure pause behavior and interval explicitly.
|
|
216
|
+
```typescript
|
|
217
|
+
useApi('/stock-prices', {
|
|
218
|
+
poll: {
|
|
219
|
+
interval: 1000,
|
|
220
|
+
whenHidden: true // ⚠️ Keep polling even if tab is backgrounded
|
|
221
|
+
}
|
|
222
|
+
})
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
#### Reactive Polling
|
|
226
|
+
You can pass a `Ref` to control polling dynamically. Perfect for "Pause/Resume" buttons.
|
|
227
|
+
```typescript
|
|
228
|
+
const interval = ref(3000)
|
|
229
|
+
|
|
230
|
+
// If you set interval.value = 0, polling stops.
|
|
231
|
+
// If you change it to 5000, it restarts with new interval immediately.
|
|
232
|
+
useApi('/live-feed', { poll: interval })
|
|
233
|
+
```
|
|
234
|
+
|
|
203
235
|
### Global Abort (Race Condition Killer)
|
|
204
236
|
Useful for complex filters where changing one filter should invalidate all pending requests on the page (or scope).
|
|
205
237
|
|
|
@@ -290,6 +322,7 @@ The main composable.
|
|
|
290
322
|
| `retry` | `boolean \| number` | `false` | Number of retries on failure. |
|
|
291
323
|
| `debounce` | `number` | `0` | Debounce time in ms. |
|
|
292
324
|
| `watch` | `WatchSource \| WatchSource[]` | `undefined` | Ref(s) to watch for auto-execution. |
|
|
325
|
+
| `poll` | `number \| { interval: number, whenHidden?: boolean } \| Ref` | `0` | Polling interval. Default pauses when hidden. |
|
|
293
326
|
| `authMode` | `'default' \| 'public'` | `'default'` | `'public'` skips token injection. |
|
|
294
327
|
| `initialData` | `T` | `null` | Initial value for `data` ref. |
|
|
295
328
|
| `onSuccess` | `(res) => void` | - | Callback on 2xx response. |
|