Skip to content

Commit

Permalink
Merge branch 'hotfix/remove_instanceOf_collection'
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosommi committed Oct 21, 2015
2 parents 7adc62c + fd1cb8d commit 4a2a12b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
7 changes: 5 additions & 2 deletions es5/lib/jsonApiModelFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ var _dovima = require("dovima");
var _dovima2 = _interopRequireDefault(_dovima);

function convertModel(model) {
if (model && typeof model.toJSON === "function" || model instanceof _dovima2["default"]) {
//HACK: this is a temporal hack to work around version issues with dovima
if (model && typeof model.toJSON === "function" && model.constructor.name === "Model" || model instanceof _dovima2["default"]) {
var attributes = model.toJSON();
var id = attributes.id;
delete attributes.id; //so it's just on the root
Expand All @@ -27,7 +28,9 @@ function convertModel(model) {
}

function JsonApiModelFormatter(models) {
if (Array.isArray(models) || models instanceof _dovima.Collection) {
if (Array.isArray(models) || models.constructor.name === "Array"
//HACK: this is a temporal hack to work around version issues with dovima
|| models.constructor.name === "Collection") {
return models.map(convertModel);
} else {
return convertModel(models);
Expand Down
9 changes: 7 additions & 2 deletions es6/lib/jsonApiModelFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import Model from "dovima";
import {Collection} from "dovima";

function convertModel(model) {
if((model && typeof (model.toJSON) === "function") || model instanceof Model) {
//HACK: this is a temporal hack to work around version issues with dovima
if((model && typeof (model.toJSON) === "function" && model.constructor.name === "Model")
|| model instanceof Model) {
let attributes = model.toJSON();
const id = attributes.id;
delete attributes.id; //so it's just on the root
Expand All @@ -17,7 +19,10 @@ function convertModel(model) {
}

export default function JsonApiModelFormatter(models) {
if(Array.isArray(models) || (models instanceof Collection)) {
if(Array.isArray(models)
|| (models.constructor.name === "Array")
//HACK: this is a temporal hack to work around version issues with dovima
|| (models.constructor.name === "Collection")) {
return models.map(convertModel);
} else {
return convertModel(models);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsonapi-model-formatter",
"version": "0.1.8",
"version": "0.1.9",
"description": "JSON API formatter for dovima models.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 4a2a12b

Please sign in to comment.