Skip to content

Commit

Permalink
Implementation (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBuchholz committed Feb 7, 2019
1 parent 2c888be commit a1a4412
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/attributes/serializable.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@
/*global _gpfAttributesMemberAttribute*/ // Shortcut for gpf.attributes.MemberAttribute
/*global _gpfAttributesUniqueAttribute*/ // Shortcut for gpf.attributes.UniqueAttribute
/*global _gpfDefine*/ // Shortcut for gpf.define
/*global _gpfIgnore*/ // Helper to remove unused parameter warning
/*global _gpfSerialPropertyCheck*/ // Check that the serializable property definition is valid
/*exported _gpfAttributesSerializable*/ // Shortcut for gpf.attributes.Serializable
/*#endif*/

var _GPF_ATTRIBUTES_SERIALIZABLE_SKIP_ = 1;

function _gpfAttributesSerializableExtractName (name) {
if (name.startsWith("_")) {
return name.substring(_GPF_ATTRIBUTES_SERIALIZABLE_SKIP_);
}
return name;
}

var _gpfAttributesSerializable = _gpfDefine({
$class: "gpf.attributes.Serializable",
$extend: _gpfAttribute,
Expand All @@ -38,7 +48,23 @@ var _gpfAttributesSerializable = _gpfDefine({
* @since 0.2.8
*/
constructor: function (property) {
this._property = _gpfSerialPropertyCheck(property);
if (property) {
this._property = Object.assign({}, property);
} else {
this._property = {};
}
},

/**
* @inheritdoc
* @since 0.2.9
*/
_check: function (member, classDefinition) {
_gpfIgnore(classDefinition);
if (!this._property.name) {
this._property.name = _gpfAttributesSerializableExtractName(member);
}
this._property = _gpfSerialPropertyCheck(this._property);
},

/**
Expand Down

0 comments on commit a1a4412

Please sign in to comment.