Browse Source

Improve toJSON of CSSRule

pull/1130/head
Artur Arseniev 8 years ago
parent
commit
b8d548aadd
  1. 20
      src/css_composer/model/CssRule.js

20
src/css_composer/model/CssRule.js

@ -1,4 +1,5 @@
import Styleable from 'domain_abstract/model/Styleable';
import { isEmpty, forEach } from 'underscore';
var Backbone = require('backbone');
var Selectors = require('selector_manager/model/Selectors');
@ -118,6 +119,25 @@ module.exports = Backbone.Model.extend(Styleable).extend({
return result;
},
toJSON(...args) {
const obj = Backbone.Model.prototype.toJSON.apply(this, args);
if (this.em.getConfig('avoidDefaults')) {
const defaults = this.defaults;
forEach(defaults, (value, key) => {
if (obj[key] === value) {
delete obj[key];
}
});
if (isEmpty(obj.selectors)) delete obj.selectors;
if (isEmpty(obj.style)) delete obj.style;
}
return obj;
},
/**
* Compare the actual model with parameters
* @param {Object} selectors Collection of selectors

Loading…
Cancel
Save