promised-models
Advanced tools
Comparing version 0.0.19 to 0.0.20
@@ -6,5 +6,19 @@ /** | ||
module.exports = Attribute.inherit({ | ||
default: NaN, | ||
/** | ||
* work around with Infinity | ||
* @override | ||
*/ | ||
toJSON: function () { | ||
var value = this.__base.apply(this, arguments); | ||
if ((value === Infinity) || (value === -Infinity)) { | ||
return String(value); | ||
} else { | ||
return value; | ||
} | ||
}, | ||
/** | ||
* @override {Attribute} | ||
@@ -24,4 +38,7 @@ */ | ||
parse: function (value) { | ||
if (value === null) { | ||
return NaN; | ||
} | ||
return Number(value); | ||
} | ||
}); |
{ | ||
"description": "promise based, typed attributes, nested models and collections", | ||
"name": "promised-models", | ||
"version": "0.0.19", | ||
"version": "0.0.20", | ||
"repository": "git@github.com:delfrrr/promised-models.git", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -147,2 +147,9 @@ # Promised Models | ||
**Note:** Returned object supposed to be serializable via `JSON.parse()`. Due to this reason `NaN` and `Infinity` are serialized in this way: | ||
``` | ||
NaN -> null | ||
Infinity -> 'Infinity' | ||
``` | ||
#### isChanged `model.isChanged([branch])` | ||
@@ -149,0 +156,0 @@ |
@@ -1,2 +0,3 @@ | ||
var expect = require('chai').expect; | ||
var expect = require('chai').expect, | ||
Model = require('../lib/model'); | ||
@@ -120,2 +121,39 @@ describe('Common', function () { | ||
}); | ||
it('should return serializable value NaN', function () { | ||
var ModelsWithNumbers = Model.inherit({ | ||
attributes: { | ||
n: Model.attributeTypes.Number | ||
} | ||
}), | ||
model1 = new ModelsWithNumbers(), | ||
model2 = new ModelsWithNumbers( | ||
JSON.parse( | ||
JSON.stringify( | ||
model1.toJSON() | ||
) | ||
) | ||
); | ||
expect(isNaN(model2.get('n'))).to.be.equal(true); | ||
}); | ||
it('should return serializable value Infinity', function () { | ||
var ModelsWithNumbers = Model.inherit({ | ||
attributes: { | ||
n: Model.attributeTypes.Number | ||
} | ||
}), | ||
model1 = new ModelsWithNumbers({ | ||
n: -Infinity | ||
}), | ||
model2 = new ModelsWithNumbers( | ||
JSON.parse( | ||
JSON.stringify( | ||
model1.toJSON() | ||
) | ||
) | ||
); | ||
expect(model2.get('n')).to.be.equal(-Infinity); | ||
}); | ||
}); | ||
@@ -122,0 +160,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
110180
2837
511