From 39d978d948ad376b2bb6ab5082940c4186762e76 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 7 Sep 2015 15:48:55 -0400 Subject: [PATCH] warn v-repeat filters that do not return Arrays --- src/directives/repeat.js | 6 ++++++ test/unit/specs/directives/repeat_spec.js | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/directives/repeat.js b/src/directives/repeat.js index 05f01de124f..015ca6705bd 100644 --- a/src/directives/repeat.js +++ b/src/directives/repeat.js @@ -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) { diff --git a/test/unit/specs/directives/repeat_spec.js b/test/unit/specs/directives/repeat_spec.js index ee98b459c98..fea9697af72 100644 --- a/test/unit/specs/directives/repeat_spec.js +++ b/test/unit/specs/directives/repeat_spec.js @@ -802,6 +802,22 @@ if (_.inBrowser) { }) }) + it('warn filters that return non-Array values', function () { + new Vue({ + el: el, + template: '
', + data: { + items: [] + }, + filters: { + test: function (val) { + return {} + } + } + }) + expect(hasWarned(_, 'should always return Arrays')).toBe(true) + }) + }) }