From fd1cb8d85cfda37c65aa0ad3898bb8886fc65fa9 Mon Sep 17 00:00:00 2001 From: nicosommi Date: Wed, 21 Oct 2015 19:56:17 -0300 Subject: [PATCH] replacement with constructor name --- es5/lib/jsonApiModelFormatter.js | 7 +++++-- es6/lib/jsonApiModelFormatter.js | 9 +++++++-- package.json | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/es5/lib/jsonApiModelFormatter.js b/es5/lib/jsonApiModelFormatter.js index ae2bef8..3c5c11b 100644 --- a/es5/lib/jsonApiModelFormatter.js +++ b/es5/lib/jsonApiModelFormatter.js @@ -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 @@ -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); diff --git a/es6/lib/jsonApiModelFormatter.js b/es6/lib/jsonApiModelFormatter.js index bca5bcd..d7693ac 100644 --- a/es6/lib/jsonApiModelFormatter.js +++ b/es6/lib/jsonApiModelFormatter.js @@ -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 @@ -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); diff --git a/package.json b/package.json index d05d97d..71a0e0e 100644 --- a/package.json +++ b/package.json @@ -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": {