Comparing version 2.0.0 to 2.0.1
@@ -110,5 +110,10 @@ module.exports = function(utils, adapter) { | ||
relationships[key] || (relationships[key] = {}); | ||
relationships[key] = data instanceof Array ? { | ||
data: data.map(buildData) | ||
} : build(data); | ||
if (data instanceof Array) { | ||
relationships[key].data = data.map(buildData); | ||
if (links[key] != null) { | ||
relationships[key].links = buildLinks(links[key]); | ||
} | ||
} else { | ||
relationships[key] = build(data); | ||
} | ||
} | ||
@@ -161,3 +166,3 @@ return relationships; | ||
if (!utils.any(this.scope.included.concat(this.scope.data), function(i) { | ||
return i.id === model.id; | ||
return i.id === model.id && i.type === model.type; | ||
})) { | ||
@@ -164,0 +169,0 @@ this.scope.included.push(model); |
@@ -22,5 +22,6 @@ module.exports = function(utils) { | ||
Store.prototype.toModel = function(rec, type, models) { | ||
var base, currentModel, data, key, links, linksAttr, model, name, ref, rel, resolve; | ||
var base, currentModel, data, key, links, model, name, ref, rel, resolve; | ||
model = utils.clone(rec.attributes) || {}; | ||
model.id = rec.id; | ||
model.type = rec.type; | ||
models[type] || (models[type] = {}); | ||
@@ -47,11 +48,5 @@ (base = models[type])[name = rec.id] || (base[name] = model); | ||
currentModel = model[key]; | ||
linksAttr = currentModel.links; | ||
currentModel.get = function(attrName) { | ||
if (attrName === 'links') { | ||
return linksAttr; | ||
} else { | ||
return currentModel[attrName]; | ||
} | ||
}; | ||
currentModel.links = links || {}; | ||
if (currentModel != null) { | ||
currentModel.links = links || {}; | ||
} | ||
} | ||
@@ -58,0 +53,0 @@ } |
{ | ||
"name": "yayson", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "A library for serializing and reading JSON API standardized data in JavaScript.", | ||
@@ -5,0 +5,0 @@ "main": "lib/yayson.js", |
# YAYSON | ||
A library for serializing and reading [JSON API](http://jsonapi.org) data in JavaScript. As of 2.0.0-beta.1 YAYSON respects JSON API Release candidate 4. | ||
A library for serializing and reading [JSON API](http://jsonapi.org) data in JavaScript. As of 2.0.0 YAYSON aims to support JSON API version 1. | ||
@@ -155,3 +155,3 @@ ## Installing | ||
``` | ||
Then you can `var yayson = require('yayson')()` use the `yayson.Presenter` and `yayson.Store` as usual. | ||
Then you can `var yayson = window.yayson()` use the `yayson.Presenter` and `yayson.Store` as usual. | ||
@@ -169,3 +169,1 @@ ### Browser support | ||
- Android | ||
Sorry, the diff of this file is not supported yet
23756
168