-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat: add onAnimationFrame
lifecycle function
#14594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 605a1f7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
preview: https://svelte-dev-git-preview-svelte-14594-svelte.vercel.app/ this is an automated message |
|
1 similar comment
|
While it's nice, this does feel more of a thing for a utility or animation library. I wouldn't call it a lifecycle function at least and expose it through |
Adjacent to #12441 |
I'm not sure it is at all. You definitely don't want to be updating the UI with |
onFrame
lifecycle functiononAnimationFrame
lifecycle function
Renamed to |
FWIW I still think this is not worth adding as it's so easy to replicate in user land - so if this is about cleaning the PR queue I'd rather close it. |
It's easy but annoying — you have to understand whether it's 'safe' to run the logic inside a $effect(() => {
let frame = requestAnimationFrame(function next() {
frame = requestAnimationFrame(next);
do_stuff();
});
return () => {
cancelAnimationFrame(frame);
};
}); ...versus this: import { onAnimationFrame } from 'svelte';
onAnimationFrame(() => {
do_stuff();
}); The intent-to-noise ratio is much higher in the second case. It's something I've wanted often enough that I do think its presence is justified, it's not just about cleaning the PR queue. |
I'm not saying it doesn't have any value, but not that it deserves to be in the same place as things like "real" life cycle hooks or other important stuff under the |
We have something similar in runed :) https://www.runed.dev/docs/utilities/animation-frames |
Just an idle thought I had while washing the dishes: should we have an
onFrame
function? It would mean for example that this demo could be written like this:Alternatively we might want to have some sort of reactive time primitive (other than
SvelteDate
) so that it could be used in deriveds too. Either way not wedded to it, just an idle thought that I thought was worth a PRBefore submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.packages/svelte/src
, add a changeset (npx changeset
).Tests and linting
pnpm test
and lint the project withpnpm lint