-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
perf(useTemplateRefsList): Optimize with shallowRef #4802
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
export function useTemplateRefsList<T = Element>(): Readonly<Ref<Readonly<TemplateRefsList<T>>>> { | ||
const refs = deepRef<unknown>([]) as Ref<TemplateRefsList<T>> | ||
export function useTemplateRefsList<T = Element>(): Readonly<ShallowRef<Readonly<TemplateRefsList<T>>>> { | ||
const refs = shallowRef<unknown>([]) as ShallowRef<TemplateRefsList<T>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we still need that cast?
const refs = shallowRef<unknown>([]) as ShallowRef<TemplateRefsList<T>> | |
const refs = shallowRef<TemplateRefsList<T>>([]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, it seems so :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because []
doesn't have a set
method?
So the type checker is right to raise that
You could instead create the empty array first, cast it and add the set method onto it
Then pass that in and get rid of line 10
export function useTemplateRefsList<T = Element>(): Readonly<Ref<Readonly<TemplateRefsList<T>>>> { | ||
const refs = deepRef<unknown>([]) as Ref<TemplateRefsList<T>> | ||
export function useTemplateRefsList<T = Element>(): Readonly<ShallowRef<Readonly<TemplateRefsList<T>>>> { | ||
const refs = shallowRef<unknown>([]) as ShallowRef<TemplateRefsList<T>> | ||
refs.value.set = (el: object | null) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we use shallow ref does this trigger the ref?
Before submitting the PR, please make sure you do the following
fixes #123
).Description
This PR optimizes
useTemplateRefsList
performance by switching toshallowRef
to avoid unnecessary deep reactivity.