diff --git a/src/item/Item.js b/src/item/Item.js index ccc95dce..81b4f4e3 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -20,7 +20,20 @@ * is unique to their type, but share the underlying properties and functions * that they inherit from Item. */ -var Item = this.Item = Base.extend(Callback, /** @lends Item# */{ +var Item = this.Item = Base.extend(Callback, { + statics: { + /** + * Override Item.extend() to merge the subclass' _serializeFields with + * the parent class' _serializeFields. + */ + extend: function(src) { + if (src._serializeFields) + src._serializeFields = Base.merge( + this.prototype._serializeFields, src._serializeFields); + return this.base.apply(this, arguments); + } + } +}, /** @lends Item# */{ // Provide information about fields to be serialized, with their defaults // that can be ommited. _serializeFields: { @@ -140,18 +153,20 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{ var props = {}, that = this; - function serialize(fields) { + function serialize(fields, compact) { for (var key in fields) { var value = that[key]; if (!Base.equals(value, fields[key])) - props[key] = Base.serialize(value, true); + props[key] = Base.serialize(value, compact); } } // Serialize fields that this Item subclass defines first - serialize(this._serializeFields); - // Serialize style fields, but only if they differ from defaults - serialize(this._style._defaults); + serialize(this._serializeFields, true); + // Serialize style fields, but only if they differ from defaults. + // Use no compacting there, since colors always need their type + // identifiers. + serialize(this._style._defaults, false); // There is no compact form for Item serialization, we always keep the // type. return [ this._type, props ]; diff --git a/src/item/Raster.js b/src/item/Raster.js index 6dcce07e..815e78d5 100644 --- a/src/item/Raster.js +++ b/src/item/Raster.js @@ -20,9 +20,7 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{ _type: 'raster', _serializeFields: { - name: null, - source: null, - matrix: new Matrix() + source: null }, // Raster doesn't make the distinction between the different bounds, // so use the same name for all of them diff --git a/src/path/Path.js b/src/path/Path.js index 382214c6..65d0e9ef 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -21,10 +21,8 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{ _type: 'path', _serializeFields: { - name: null, segments: [], - closed: false, - matrix: new Matrix() + closed: false }, /**