Skip to content

Commit

Permalink
warn v-repeat filters that do not return Arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Sep 7, 2015
1 parent 3b9fb2d commit 39d978d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/directives/repeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ module.exports = {
*/

update: function (data) {
if (process.env.NODE_ENV !== 'production' && !_.isArray(data)) {
_.warn(
'v-repeat pre-converts Objects into Arrays, and ' +
'v-repeat filters should always return Arrays.'
)
}
if (this.componentId) {
var state = this.componentState
if (state === UNRESOLVED) {
Expand Down
16 changes: 16 additions & 0 deletions test/unit/specs/directives/repeat_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,22 @@ if (_.inBrowser) {
})
})

it('warn filters that return non-Array values', function () {
new Vue({
el: el,
template: '<div v-repeat="items | test"></div>',
data: {
items: []
},
filters: {
test: function (val) {
return {}
}
}
})
expect(hasWarned(_, 'should always return Arrays')).toBe(true)
})

})
}

Expand Down

0 comments on commit 39d978d

Please sign in to comment.