feat: support configurable schedulers for timed composables#5070
feat: support configurable schedulers for timed composables#5070
Conversation
@vueuse/components
@vueuse/core
@vueuse/electron
@vueuse/firebase
@vueuse/integrations
@vueuse/math
@vueuse/metadata
@vueuse/nuxt
@vueuse/router
@vueuse/rxjs
@vueuse/shared
commit: |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #5070 +/- ##
==========================================
+ Coverage 65.93% 66.72% +0.78%
==========================================
Files 365 365
Lines 14565 14624 +59
Branches 2388 2409 +21
==========================================
+ Hits 9604 9758 +154
+ Misses 4950 4855 -95
Partials 11 11 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I would be happy to see |
useIntervalFn-based composables and unify options| /** | ||
| * Custom scheduler to use for interval execution. | ||
| * | ||
| * @default useRafFn |
There was a problem hiding this comment.
The only difference is the default value in the JSDoc; I'm not sure if there's a better way to make it more noticeable to users.
| /** | ||
| * Start the interval immediately | ||
| * | ||
| * @default false |
| }, options?.interval ?? 1000, { immediate: options?.immediate ?? false }) | ||
| const { | ||
| scheduler = useIntervalFn, | ||
| interval = 1000, |
There was a problem hiding this comment.
I’d like to get some opinions on whether it’s necessary to explicitly set default values in the top-level functions, rather than passing undefined and letting the underlying scheduler handle it.
Just want to note that different functions handle this differently, and all properties in SchedulerOptions have this situation.
Absolutely agree! I did run into some issues earlier, but after some more thought, I realized I was overcomplicating it. I've now found a clean solution and have pushed the updates. |
| */ | ||
| export function useIntervalFn(cb: Fn, interval: MaybeRefOrGetter<number> = 1000, options: UseIntervalFnOptions = {}): UseIntervalFnReturn { | ||
| export function useIntervalFn(cb: Fn, interval: MaybeRefOrGetter<number>, options?: UseIntervalFnOptions): UseIntervalFnReturn | ||
| export function useIntervalFn(cb: Fn, options?: SchedulerOptions): UseIntervalFnReturn |
There was a problem hiding this comment.
Overloaded the method and implemented the Scheduler interface.
|
Since this PR touches multiple files, I'd recommend adding tests to prevent regressions before we merge. |
|
I'd like to gather some input on:
|
Before submitting the PR, please make sure you do the following
fixes #123).Description
This PR unifies the options of composables built on top of
useIntervalFnand introduces a customizable scheduler option:useIntervaluseCountDownuseMemoryuseVibrateuseWebSocket- a bit specialThere are also a few functions that currently allow choosing between
useRafFnanduseIntervalFnthrough anintervaloption.I didn’t make changes to those in this PR, and I’d like to hear everyone’s thoughts on this. If we can make the custom scheduler compatible with bothuseIntervalFnanduseRafFn, it will avoid having to import bothuseIntervalFnanduseRafFn.useElementByPointuseNowuseTimestampWe can update the configurations documentation once we’ve discussed and agreed on a suitable approach.Additional context
Related: #5043