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

fix: [Table] #295 data reactivity issue #296

Merged
merged 5 commits into from
Jan 18, 2024

Conversation

mattgoud
Copy link
Collaborator

❓ Types of changes

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality)
  • πŸ“¦ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

data reactivity issue

πŸ“ Checklist

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes
  • The component exists on old Prestashop UIKit and my pull request on migrating documentation is accepted.

@mattgoud mattgoud requested a review from kktos January 17, 2024 17:36
@mattgoud mattgoud self-assigned this Jan 17, 2024
@mattgoud mattgoud changed the title fix: #295 data reactivity issue fix: [Table] #295 data reactivity issue Jan 17, 2024
@@ -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')
Copy link

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);

Copy link

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.

Copy link

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

Copy link
Collaborator Author

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

Copy link
Collaborator Author

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)

Copy link
Collaborator Author

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...

@mattgoud mattgoud requested a review from kktos January 18, 2024 11:29
Copy link

@kktos kktos left a 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.
;)

@ThbPS ThbPS requested a review from kktos January 18, 2024 11:43
@mattgoud mattgoud requested a review from ThbPS January 18, 2024 13:20
@mattgoud
Copy link
Collaborator Author

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

@mattgoud mattgoud merged commit 6f4459a into main Jan 18, 2024
3 of 5 checks passed
@mattgoud mattgoud deleted the bug/table-data-reactivity-issue branch January 18, 2024 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants