Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(MdTable): emit selected / update event only when selected item(s) really changed #1585

Merged
merged 2 commits into from
Mar 7, 2018
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
25 changes: 21 additions & 4 deletions src/components/MdTable/MdTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,28 @@
this.MdTable.hasValue = this.hasValue
}
},
'MdTable.selectedItems' (val) {
this.select(val)
'MdTable.selectedItems' (val, old) {
Copy link
Member

Choose a reason for hiding this comment

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

I think this method is way complex. Maybe we can break it in some small functions to better describe it.

Copy link
Member

Choose a reason for hiding this comment

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

Like: val.length !== old.length) ? true : !val.every((item, index) => item == old[index]

let changed = (() => {
let isValEmpty = !val || val.length === 0
let isOldEmpty = !old || old.length === 0

if (isValEmpty && isOldEmpty) {
return false
} else if (!isValEmpty && !isOldEmpty) {
return (val.length !== old.length) ? true : !val.every((item, index) => item == old[index])
} else {
return true
}
})()

if (changed) {
this.select(val)
}
},
'MdTable.singleSelection' (val) {
this.select(val)
'MdTable.singleSelection' (val, old) {
if (val != old) {
this.select(val)
}
},
mdSelectedValue () {
this.syncSelectedValue()
Expand Down