|
|
@@ -403,11 +403,7 @@ const vFor = {
|
|
|
var primitive = !isObject(value)
|
|
|
var id
|
|
|
if (key || trackByKey || primitive) {
|
|
|
- id = trackByKey
|
|
|
- ? trackByKey === '$index'
|
|
|
- ? index
|
|
|
- : getPath(value, trackByKey)
|
|
|
- : (key || value)
|
|
|
+ id = getTrackByKey(index, key, value, trackByKey)
|
|
|
if (!cache[id]) {
|
|
|
cache[id] = frag
|
|
|
} else if (trackByKey !== '$index') {
|
|
|
@@ -444,11 +440,7 @@ const vFor = {
|
|
|
var primitive = !isObject(value)
|
|
|
var frag
|
|
|
if (key || trackByKey || primitive) {
|
|
|
- var id = trackByKey
|
|
|
- ? trackByKey === '$index'
|
|
|
- ? index
|
|
|
- : getPath(value, trackByKey)
|
|
|
- : (key || value)
|
|
|
+ var id = getTrackByKey(index, key, value, trackByKey)
|
|
|
frag = this.cache[id]
|
|
|
} else {
|
|
|
frag = value[this.id]
|
|
|
@@ -476,11 +468,7 @@ const vFor = {
|
|
|
var key = hasOwn(scope, '$key') && scope.$key
|
|
|
var primitive = !isObject(value)
|
|
|
if (trackByKey || key || primitive) {
|
|
|
- var id = trackByKey
|
|
|
- ? trackByKey === '$index'
|
|
|
- ? index
|
|
|
- : getPath(value, trackByKey)
|
|
|
- : (key || value)
|
|
|
+ var id = getTrackByKey(index, key, value, trackByKey)
|
|
|
this.cache[id] = null
|
|
|
} else {
|
|
|
value[this.id] = null
|
|
|
@@ -635,6 +623,25 @@ function range (n) {
|
|
|
return ret
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Get the track by key for an item.
|
|
|
+ *
|
|
|
+ * @param {Number} index
|
|
|
+ * @param {String} key
|
|
|
+ * @param {*} value
|
|
|
+ * @param {String} [trackByKey]
|
|
|
+ */
|
|
|
+
|
|
|
+function getTrackByKey (index, key, value, trackByKey) {
|
|
|
+ return trackByKey
|
|
|
+ ? trackByKey === '$index'
|
|
|
+ ? index
|
|
|
+ : trackByKey.charAt(0).match(/\w/)
|
|
|
+ ? getPath(value, trackByKey)
|
|
|
+ : value[trackByKey]
|
|
|
+ : (key || value)
|
|
|
+}
|
|
|
+
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
vFor.warnDuplicate = function (value) {
|
|
|
warn(
|