Skip to content

Commit

Permalink
Remove identifier sync back in v-repeat
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Evan You committed Apr 25, 2014
1 parent 489ded4 commit b50e5a5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 95 deletions.
10 changes: 0 additions & 10 deletions src/directives/repeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,6 @@ module.exports = {
(raw || data).__emitter__[this.identifier] = true
}

if (wrap) {
var self = this,
sync = function (val) {
self.lock = true
self.collection.$set(vm.$index, val)
self.lock = false
}
vm.$compiler.observer.on('change:' + alias, sync)
}

return vm

},
Expand Down
15 changes: 0 additions & 15 deletions test/functional/fixtures/repeated-primitive.html

This file was deleted.

37 changes: 0 additions & 37 deletions test/functional/specs/repeated-primitive.js

This file was deleted.

39 changes: 6 additions & 33 deletions test/unit/specs/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -852,18 +852,12 @@ describe('Directives', function () {
}
})

it('should work with primitive values', function (done) {
var triggeredChange = 0
it('should work with primitive values', function () {
var v = new Vue({
template: '<span v-repeat="tags" v-ref="tags">{{$value}}</span>',
template: '<span v-repeat="tags">{{$value}}</span>',
data: {
tags: ['a', 'b', 'c']
},
created: function () {
this.$watch('tags', function () {
triggeredChange++
})
},
computed: {
concat: function () {
return this.tags.join(',')
Expand All @@ -872,13 +866,6 @@ describe('Directives', function () {
})
assert.strictEqual(v.concat, 'a,b,c')
assert.strictEqual(v.$el.textContent, 'abc')
v.$.tags[0].$value = 'd'
assert.strictEqual(v.tags[0], 'd')
nextTick(function () {
assert.strictEqual(triggeredChange, 1)
assert.strictEqual(v.concat, 'd,b,c')
done()
})
})

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

})

it('should accept arg for aliasing on primitive arrays', function (done) {
it('should accept arg for aliasing on primitive arrays', function () {

var v = new Vue({
template: '<span v-repeat="item:items" v-ref="items">{{item}}</span>',
template: '<span v-repeat="item:items" >{{item}}</span>',
data: {
items: [1,2,3]
}
})
assert.strictEqual(v.$el.textContent, '123')
v.$.items[0].item = 2

nextTick(function () {
assert.strictEqual(v.$el.textContent, '223')
assert.deepEqual(v.items, [2,2,3])
done()
})

})

it('should accept arg for aliasing on object arrays', function (done) {
it('should accept arg for aliasing on object arrays', function () {

var v = new Vue({
template: '<span v-repeat="item:items" v-ref="items">{{item.id}}</span>',
template: '<span v-repeat="item:items">{{item.id}}</span>',
data: {
items: [{id:1},{id:2},{id:3}]
}
})
assert.strictEqual(v.$el.textContent, '123')
v.$.items[0].item = { id: 2 }

nextTick(function () {
assert.strictEqual(v.$el.textContent, '223')
assert.strictEqual(v.items[0].id, 2)
done()
})

})

Expand Down

0 comments on commit b50e5a5

Please sign in to comment.