8000 Remove identifier sync back in v-repeat · hwclass/vue@b50e5a5 · GitHub
[go: up one dir, main page]

Skip to content

Commit b50e5a5

Browse files
author
Evan You
committed
Remove identifier sync back in v-repeat
The auto-sync back when an identifier is used causes issues such as vuejs#213 and vuejs#234, while the feature is a rarely used edge case that is also a bit magical. It can be easily circumvented by using object arrays instead of primitive ones, and the sync-back is better left in userland for those who really need it. For reference, Angular also doesn't support sync back for primitive values.
1 parent 489ded4 commit b50e5a5

File tree

4 files changed

+6
-95
lines changed

4 files changed

+6
-95
lines changed

src/directives/repeat.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,6 @@ module.exports = {
212212
(raw || data).__emitter__[this.identifier] = true
213213
}
214214

215-
if (wrap) {
216-
var self = this,
217-
sync = function (val) {
218-
self.lock = true
219-
self.collection.$set(vm.$index, val)
220-
self.lock = false
221-
}
222-
vm.$compiler.observer.on('change:' + alias, sync)
223-
}
224-
225215
return vm
226216

227217
},

test/functional/fixtures/repeated-primitive.html

Lines changed: 0 additions & 15 deletions
This file was deleted.

test/functional/specs/repeated-primitive.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

test/unit/specs/directives.js

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -852,18 +852,12 @@ describe('Directives', function () {
852852
}
853853
})
854854

855-
it('should work with primitive values', function (done) {
856-
var triggeredChange = 0
855+
it('should work with primitive values', function () {
857856
var v = new Vue({
858-
template: '<span v-repeat="tags" v-ref="tags">{{$value}}</span>',
857+
template: '<span v-repeat="tags">{{$value}}</span>',
859858
data: {
860859
tags: ['a', 'b', 'c']
861860
},
862-
created: function () {
863-
this.$watch('tags', function () {
864-
triggeredChange++
865-
})
866-
},
867861
computed: {
868862
concat: function () {
869863
return this.tags.join(',')
@@ -872,13 +866,6 @@ describe('Directives', function () {
872866
})
873867
assert.strictEqual(v.concat, 'a,b,c')
874868
assert.strictEqual(v.$el.textContent, 'abc')
875-
v.$.tags[0].$value = 'd'
876-
assert.strictEqual(v.tags[0], 'd')
877-
nextTick(function () {
878-
assert.strictEqual(triggeredChange, 1)
879-
assert.strictEqual(v.concat, 'd,b,c')
880-
done()
881-
})
882869
})
883870

884871
it('should diff and reuse existing VMs when reseting arrays', function (done) {
@@ -955,41 +942,27 @@ describe('Directives', function () {
955942

956943
})
957944

958-
it('should accept arg for aliasing on primitive arrays', function (done) {
945+
it('should accept arg for aliasing on primitive arrays', function () {
959946

960947
var v = new Vue({
961-
template: '<span v-repeat="item:items" v-ref="items">{{item}}</span>',
948+
template: '<span v-repeat="item:items" >{{item}}</span>',
962949
data: {
963950
items: [1,2,3]
964951
}
965952
})
966953
assert.strictEqual(v.$el.textContent, '123')
967-
v.$.items[0].item = 2
968-
969-
nextTick(function () {
970-
assert.strictEqual(v.$el.textContent, '223')
971-
assert.deepEqual(v.items, [2,2,3])
972-
done()
973-
})
974954

975955
})
976956

977-
it('should accept arg for aliasing on object arrays', function (done) {
957+
it('should accept arg for aliasing on object arrays', function () {
978958

979959
var v = new Vue({
980-
template: '<span v-repeat="item:items" v-ref="items">{{item.id}}</span>',
960+
template: '<span v-repeat="item:items">{{item.id}}</span>',
981961
data: {
982962
items: [{id:1},{id:2},{id:3}]
983963
}
984964
})
985965
assert.strictEqual(v.$el.textContent, '123')
986-
v.$.items[0].item = { id: 2 }
987-
988-
nextTick(function () {
989-
assert.strictEqual(v.$el.textContent, '223')
990-
assert.strictEqual(v.items[0].id, 2)
991-
done()
992-
})
993966

994967
})
995968

0 commit comments

Comments
 (0)
0