Comparing version 2.0.0-beta.1 to 2.0.0-beta.2
@@ -14,3 +14,3 @@ var Adapter; | ||
Adapter.id = function(model) { | ||
return this.get(model, 'id'); | ||
return "" + (this.get(model, 'id')); | ||
}; | ||
@@ -17,0 +17,0 @@ |
@@ -31,3 +31,3 @@ module.exports = function(utils, adapter) { | ||
Presenter.prototype.id = function(instance) { | ||
return adapter.id(instance); | ||
return this.constructor.adapter.id(instance); | ||
}; | ||
@@ -46,3 +46,4 @@ | ||
} | ||
attributes = utils.clone(adapter.get(instance)); | ||
attributes = utils.clone(this.constructor.adapter.get(instance)); | ||
delete attributes['id']; | ||
relationships = this.relationships(); | ||
@@ -64,3 +65,3 @@ for (key in relationships) { | ||
presenter = new factory(scope); | ||
data = adapter.get(instance, key); | ||
data = this.constructor.adapter.get(instance, key); | ||
if (data != null) { | ||
@@ -86,17 +87,19 @@ _results.push(presenter.toJSON(data, { | ||
for (key in rels) { | ||
data = adapter.get(instance, key); | ||
data = this.constructor.adapter.get(instance, key); | ||
presenter = rels[key]; | ||
build = function(d) { | ||
var rel; | ||
rel = { | ||
data: { | ||
id: adapter.id(d), | ||
type: presenter.prototype.type | ||
build = (function(_this) { | ||
return function(d) { | ||
var rel; | ||
rel = { | ||
data: { | ||
id: _this.constructor.adapter.id(d), | ||
type: presenter.prototype.type | ||
} | ||
}; | ||
if (links[key] != null) { | ||
rel.links = buildLinks(links[key]); | ||
} | ||
return rel; | ||
}; | ||
if (links[key] != null) { | ||
rel.links = buildLinks(links[key]); | ||
} | ||
return rel; | ||
}; | ||
})(this); | ||
relationships || (relationships = {}); | ||
@@ -103,0 +106,0 @@ relationships[key] || (relationships[key] = {}); |
{ | ||
"name": "yayson", | ||
"version": "2.0.0-beta.1", | ||
"version": "2.0.0-beta.2", | ||
"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 standardized 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-beta.1 YAYSON respects JSON API Release candidate 4. | ||
@@ -11,3 +11,2 @@ ## Installing | ||
$ npm install yayson --pre --save | ||
``` | ||
@@ -96,2 +95,4 @@ | ||
### Sequalize support | ||
By default it is set up to handle standard JS objects. You can also make | ||
@@ -105,2 +106,4 @@ it handle Sequalize.js models like this: | ||
Take a look at the SequalizeAdapter if you want to extend YAYSON to your ORM. Pull requests are welccome :) | ||
### Metadata | ||
@@ -149,7 +152,9 @@ | ||
Copy the file `dist/yayson.js` to your project. Then simply include it: | ||
Recommended way is to use it via [webpack](https://github.com/webpack/webpack) or similar build system wich lets you just require the package as usual. | ||
If you just want to try it out, copy the file `dist/yayson.js` to your project. Then simply include it: | ||
```html | ||
<script src="./lib/yayson.js"></script> | ||
``` | ||
Then you can `var yayson = require('yayson')()` use the `yayson.Presenter` and `yayson.Store` as usual. IN THE BROWSER! | ||
Then you can `var yayson = require('yayson')()` use the `yayson.Presenter` and `yayson.Store` as usual. | ||
@@ -159,11 +164,11 @@ ### Browser support | ||
#### Tested | ||
Chrome | ||
Firefox | ||
Safari | ||
Safari iOS | ||
- Chrome | ||
- Firefox | ||
- Safari | ||
- Safari iOS | ||
#### Untested, but should work | ||
IE 9+ | ||
Android | ||
- IE 9+ | ||
- Android | ||
22627
573
170