Skip to content

Commit

Permalink
Version bump. Add support for toJSON of null valued attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
relativityboy committed Sep 10, 2017
1 parent fa0c257 commit 0a2f2e4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion log.md
@@ -1,7 +1,8 @@
## Log:
###2017.09
* .toJSON - added support for null value attributes. :(
###2017.04
* Full support for dotPath on collections.

###2017.03
* More tests (now above 90%)
* Added support for dotPath to Models.
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "dw-backbone",
"version": "0.7.0",
"version": "0.7.1",
"description": "",
"main": "src/base.js",
"scripts": {
Expand Down
9 changes: 6 additions & 3 deletions src/base.js
Expand Up @@ -581,11 +581,14 @@
_.each(keys, function(key) {
if(typeof this.attributes[key] !== 'undefined') {
rspAttrName = (map.attrs[key] && map.attrs[key].fieldName) ? map.attrs[key].fieldName : converter(key);
rsp[rspAttrName] = (typeof this.attributes[key].toJSON === 'function') ? this.attributes[key].toJSON(options, mode) : (typeof this.attributes[key] === 'object') ? converter(this.attributes[key]) : this.attributes[key];

rsp[rspAttrName] = (('object' !== typeof this.attributes[key]) || (null === this.attributes[key]))? this.attributes[key] :
('function' === typeof this.attributes[key].toJSON) ? this.attributes[key].toJSON(options, mode) : converter(this.attributes[key]);

if (map.attrs[key] && map.attrs[key].fn) {
if (map.attrs[key].fn == 'stringify') {
if (map.attrs[key].fn === 'stringify') {
rsp[rspAttrName] = JSON.stringify(rsp[rspAttrName]);
} else if (map.attrs[key].fn == 'parse') {
} else if (map.attrs[key].fn === 'parse') {
rsp[rspAttrName] = JSON.parse(rsp[rspAttrName]);
} else if (typeof map.attrs[key].fn === 'function') {
rsp[rspAttrName] = map.attrs[key].fn.call(this, rsp[rspAttrName]);
Expand Down
3 changes: 2 additions & 1 deletion test/base.model.js
Expand Up @@ -268,7 +268,8 @@ describe('Base.Model', function() {
c:'apple',
object:{
'pear':'fruit',
'banana':'more fruit'
'banana':'more fruit',
'mango':null
}
};
model = new Model(attributes);
Expand Down
3 changes: 2 additions & 1 deletion test/base.model.jsonmap.from.js
Expand Up @@ -37,7 +37,8 @@ describe("Base.Model.jsonMap.<mode>.from - transform input {...} on 'new Base.Mo
c:'apple',
objectOne:{
'pear':'fruit',
'banana':'more fruit'
'banana':'more fruit',
'mango':null
},
object_two:{
'pear':'glim',
Expand Down

0 comments on commit 0a2f2e4

Please sign in to comment.