-
Notifications
You must be signed in to change notification settings - Fork 1
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
fix: [Table] #295 data reactivity issue #296
Conversation
@@ -285,7 +285,7 @@ const ScrollBarPosition = ref<string>('left') | |||
const lastScrollLeft = ref(0) | |||
const sortOrder = ref([]) | |||
const sortIcon = ref({}) | |||
const data = ref([...props.items]) | |||
const data = toRef(props, 'items') |
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.
this is a readonly var so it should be better to have :
const data = toRef(() => props.items);
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.
and I just realised why there was a copy of the data here. The sort !
So as you're mutating the value, you made a copy of it beforehand.
That could be costly, depending on the data size.
It could be worth having an option for that: allowsToMutate or not.
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.
there is a typo:
PuikTableScrollBarPosistion
should be
PuikTableScrollBarPosition
table.ts#L16
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.
yes that's what I did but it generates errors for me, the function expects arguments however it seems to respect the signature as in the example in the doc:
// creates a readonly ref that calls the getter on .value access
toRef(() => props.foo)
I will use watch() as an alternative
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.
and I just realised why there was a copy of the data here. The sort ! So as you're mutating the value, you made a copy of it beforehand. That could be costly, depending on the data size. It could be worth having an option for that: allowsToMutate or not.
yes, it can be expensive, otherwise there is a sortFromServer prop which prevents sorting on the client side. Only a SortOptions type payload is sent (which can be useful for building a server-side query instead)
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.
yes that's what I did but it generates errors for me, the function expects arguments however it seems to respect the signature as in the example in the doc:
// creates a readonly ref that calls the getter on .value access toRef(() => props.foo)
I will use watch() as an alternative
ha! it must be because the project was still in 4.2.47...
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.
Each time you find a bug, it is good practice to add a UT for it.
Here, you may add a test with items =[] then change it and see if the table is updated.
It'll be a good guard against regression.
;)
yes @kktos, done |
β Types of changes
π Description
data reactivity issue
π Checklist