Skip to content
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

refactor(svelte): migrate to svelte 5 #391

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions packages/svelte/src/lib/Dotlottie.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

let {
autoplay = false,
backgroundColor,
backgroundColor = '',
data,
loop = false,
mode = 'forward',
Expand Down Expand Up @@ -98,14 +98,13 @@
});

$effect(() => {
console.log(speed);
if (dotLottie && dotLottie.isLoaded && typeof speed == 'number') {
if (dotLottie && typeof speed == 'number' && dotLottie.isLoaded) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed order of conditions, cause isLoaded is not reactive which blocking svelte from getting to next reactive object which is speed.

thanks to sveltejs/svelte#14517 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @theashraf, can i get a review on this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@moonlitgrace Sorry for the late reply. Is the PR ready for review?

Before that, I'm not sure if Svelte 5 is backward compatible with Svelte 4. Is that the case? If it is, we’ll also need to update the peer dependencies of the dotlottie-svelte package to include both v4 and v5 of Svelte.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @theashraf, wishing you a very happy new year (a bit late ik) and sry for the delay.

yes, PR is ready for review. if i remember correctly, i actually requested this change, let me know if you have any constraints regarding the ordering.

I'm not sure if Svelte 5 is backward compatible with Svelte 4. Is that the case?

it should be, but i didnt test it. something seemed off last time i tried running a Svelte 4 project, everything changed/updated to Svelte 5. well, i will give it another shot and update you.

dotLottie.setSpeed(speed);
}
});

$effect(() => {
if (dotLottie && dotLottie.isLoaded && typeof useFrameInterpolation == 'boolean') {
if (dotLottie && typeof useFrameInterpolation == 'boolean' && dotLottie.isLoaded) {
dotLottie.setUseFrameInterpolation(useFrameInterpolation);
}
});
Expand All @@ -125,19 +124,19 @@
});

$effect(() => {
if (dotLottie && dotLottie.isLoaded && typeof loop == 'boolean') {
if (dotLottie && typeof loop == 'boolean' && dotLottie.isLoaded) {
dotLottie.setLoop(loop);
}
});

$effect(() => {
if (dotLottie) {
dotLottie.setBackgroundColor(backgroundColor || '');
if (dotLottie && typeof backgroundColor == 'string' && dotLottie.isLoaded) {
dotLottie.setBackgroundColor(backgroundColor);
}
});

$effect(() => {
if (dotLottie && dotLottie.isLoaded && typeof mode == 'string') {
if (dotLottie && typeof mode == 'string' && dotLottie.isLoaded) {
dotLottie.setMode(mode);
}
});
Expand Down
5 changes: 4 additions & 1 deletion packages/svelte/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
let isPaused = $state(false);
let isStopped = $state(false);
let isFrozen = $state(false);
let loop = true;
let loop = $state(true);
let backgroundColor = $state('#00000000');
let speed = $state(1);
let hasMultipleAnimations = $state(false);
Expand Down Expand Up @@ -49,6 +49,7 @@
isPlaying = true;
isPaused = false;
isStopped = false;
isFrozen = false;
});
dotLottie.addEventListener('pause', () => {
isPlaying = false;
Expand Down Expand Up @@ -96,6 +97,7 @@
<button onclick={() => dotLottie?.stop()}>Stop</button>
<button onclick={() => dotLottie?.freeze()}>Freeze</button>
<button onclick={() => dotLottie?.unfreeze()}>Unfreeze</button>
<button onclick={() => (loop = !loop)}>Toggle loop</button>
<button onclick={() => (speed += 0.5)}>Increase speed</button>
<button onclick={() => (speed -= 0.5)}>Decrease speed</button>
<button onclick={next} disabled={!hasMultipleAnimations}>Next animation</button>
Expand All @@ -122,6 +124,7 @@
<input type="color" bind:value={backgroundColor} />
<ul>
<li>Speed: {speed}</li>
<li>Looped: {loop}</li>
<li>Loaded: {isLoaded}</li>
<li>Playing: {isPlaying}</li>
<li>Paused: {isPaused}</li>
Expand Down
Loading