feat(raf): add frameloop utils.#824
Conversation
- Added `useFrameloop` util to use unified request animation frame calls. - Added `createScheduledFrameloop` to handle request animation frame from external sources. - Fixed `createRAF` cleanup for id `0` by using `null` instead.
|
packages/raf/src/index.ts
Outdated
| } | ||
|
|
||
| /** | ||
| * Returns an advanced primitive factory function (that has an API similar to `createRAF`) to handle multiple animation frame callbacks in a single batched `requestAnimationFrame`, avoiding the overhead of scheduling multiple animation frames outside of a batch and making them all sync on the same delta. |
There was a problem hiding this comment.
The explanation is way too complex. "A version of createRAF that batches multiple frames within the same render cycle instead of skipping them ."
packages/raf/src/index.ts
Outdated
| * | ||
| * The idea behind this is for more complex use cases, where you need scheduling and want to avoid potential issues arising from running more than one `requestAnimationFrame`. | ||
| * | ||
| * @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/raf#createScheduledFrameloop |
There was a problem hiding this comment.
You seem to have forgotten to update the README.md
packages/raf/src/index.ts
Outdated
| automatic?: MaybeAccessor<boolean>, | ||
| ) => [ | ||
| queued: Accessor<boolean>, | ||
| queue: VoidFunction, |
There was a problem hiding this comment.
Not that I generally dislike this addition, but why not extract the queue logic into a separate primitive that can also be used with the normal createRAF?
There was a problem hiding this comment.
Could I get some guidance on how that would be structured? Do you propose adding the queue logic as a separate create helper?
There was a problem hiding this comment.
Something like
function queueCallbacks(
...initialCallbacks: (() => void)[]
): [callback: () => void, { add: (cb) => void, del: (cb) => void }] {
...
}|
Sorry for the delay on this, the end of the year tends to be really busy. I was starting to re-visit the approach itself and maybe landed into a nicer primitive set, want to hear your opinions on this @atk (I can leave it as an update on this PR, but I don't think this is the right approach for this):
|
atk
left a comment
There was a problem hiding this comment.
I don't see my last points addressed, also, the tests seem to fail.
There was a problem hiding this comment.
You need to add your primitives to primitive.list.
Added
createCallbacksSetutil to unify calling multiple void callbacks stored in aReactiveSet.Added
createScheduledLoopto handle external animation loops, such asmotion's frame util.Added
useGlobalRAFutil to handle unified request animation frame calls.Fixed
createRAFcleanup for id0by usingnullinstead.Addresses this proposal #822.