Skip to content

Commit d83a2b1

Browse files
authored
fix(perf): reactivity issues with bvAttrs and bvListeners (closes #5520) (#5753)
* fix(b-table): reactivity issues for dynamically added listeners * Revert "fix(b-table): reactivity issues for dynamically added listeners" This reverts commit 70fe168. * Update cache.js * Update cache.js
1 parent 2f7d3c8 commit d83a2b1

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/utils/cache.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
1-
import { hasOwnProperty } from './object'
1+
import cloneDeep from './clone-deep'
2+
import looseEqual from './loose-equal'
3+
import { hasOwnProperty, keys } from './object'
4+
5+
const isEmpty = value => !value || keys(value).length === 0
26

37
export const makePropWatcher = propName => ({
4-
handler(newVal, oldVal) {
5-
for (const key in oldVal) {
6-
if (!hasOwnProperty(newVal, key)) {
8+
handler(newValue, oldValue) {
9+
if (looseEqual(newValue, oldValue)) {
10+
return
11+
}
12+
if (isEmpty(newValue) || isEmpty(oldValue)) {
13+
this[propName] = cloneDeep(newValue)
14+
return
15+
}
16+
for (const key in oldValue) {
17+
if (!hasOwnProperty(newValue, key)) {
718
this.$delete(this.$data[propName], key)
819
}
920
}
10-
for (const key in newVal) {
11-
this.$set(this.$data[propName], key, newVal[key])
21+
for (const key in newValue) {
22+
this.$set(this.$data[propName], key, newValue[key])
1223
}
1324
}
1425
})
1526

1627
export const makePropCacheMixin = (propName, proxyPropName) => ({
1728
data() {
18-
return {
19-
[proxyPropName]: {}
20-
}
29+
return { [proxyPropName]: cloneDeep(this[propName]) }
2130
},
2231
watch: {
2332
// Work around unwanted re-renders: https://github.com/vuejs/vue/issues/10115
2433
[propName]: makePropWatcher(proxyPropName)
25-
},
26-
created() {
27-
this[proxyPropName] = { ...this[propName] }
2834
}
2935
})

0 commit comments

Comments
 (0)