From c8758323adeecea8271ad950e5e6fabc6b34f2fc Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 3 Jul 2012 10:47:42 +0200 Subject: o Making sure each query has a data array. --- index.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index c0d0378..bcc6927 100644 --- a/index.js +++ b/index.js @@ -8,15 +8,21 @@ function fromObject(root) { root.collection = _.isObject(root.collection) ? root.collection : {}; var c = root.collection; c.version = _.isString(c.version) ? c.version : "1.0"; - c.items = _.isArray(c.items) ? c.items : []; - c.links = _.isArray(c.links) ? c.links : []; - c.queries = _.isArray(c.queries) ? c.queries : []; - c.templates = _.isArray(c.templates) ? c.templates : []; + c.items = _.isArray(c.items) ? c.items : []; _.each(c.items, function(item) { item.links = _.isArray(item.links) ? item.links : []; }); + c.links = _.isArray(c.links) ? c.links : []; + + c.queries = _.isArray(c.queries) ? c.queries : []; + _.each(c.queries, function(query) { + query.data = _.isArray(query.data) ? query.data : []; + }); + + c.templates = _.isArray(c.templates) ? c.templates : []; + // TODO: make un-enumerable root.mapItemData = function(f) { return _.map(this.collection.items, function(item) { -- cgit v1.2.3