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

perf: reduce the unnecessary use of ref #526

Merged
merged 2 commits into from
Mar 17, 2024
Merged
Changes from all commits
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
10 changes: 5 additions & 5 deletions packages/vue3-lottie/src/vue3-lottie.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ export default defineComponent({
},

setup(props, { emit: emits }) {
const animationData = ref<any>()
const lottieAnimationContainer = ref<HTMLDivElement>()

let animationData: any
let lottieAnimation: AnimationItem | null = null
let direction: AnimationDirection = 1

Expand All @@ -131,14 +131,14 @@ export default defineComponent({

const responseJSON = await response.json()

animationData.value = responseJSON
animationData = responseJSON
} catch (error) {
console.error(error)
return
}
} else if (isEqual(props.animationData, {}) === false) {
// clone the animationData to prevent it from being mutated
animationData.value = cloneDeep(props.animationData)
animationData = cloneDeep(props.animationData)
} else {
throw new Error(
'You must provide either animationLink or animationData',
Expand All @@ -153,7 +153,7 @@ export default defineComponent({
if (!lottieAnimationContainer.value) return

// check if the animationData has been loaded
if (!animationData.value) return
if (!animationData) return

// destroy the animation if it already exists
lottieAnimation?.destroy()
Expand Down Expand Up @@ -187,7 +187,7 @@ export default defineComponent({
renderer: props.renderer,
loop: loop,
autoplay: autoPlay,
animationData: animationData.value,
animationData: animationData,
assetsPath: props.assetsPath,
}

Expand Down