From 717a4f41a4aaa2ea4923e644902e9571c4c651a2 Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Fri, 15 Sep 2017 11:43:27 -0700 Subject: [PATCH] Adds `Polymer.BasicElement` Provides minimal element starting point using PropertyAccessors to create properties using a properties object similar to Polymer.Element. No template or binding support is provided. --- lib/elements/basic-element.html | 100 ++++++++ lib/mixins/property-accessors.html | 24 +- test/unit/polymer.basic-element.html | 360 +++++++++++++++++++++++++++ 3 files changed, 482 insertions(+), 2 deletions(-) create mode 100644 lib/elements/basic-element.html create mode 100644 test/unit/polymer.basic-element.html diff --git a/lib/elements/basic-element.html b/lib/elements/basic-element.html new file mode 100644 index 0000000000..00bb7efd2f --- /dev/null +++ b/lib/elements/basic-element.html @@ -0,0 +1,100 @@ + + + + + + + diff --git a/lib/mixins/property-accessors.html b/lib/mixins/property-accessors.html index c6ea6abaeb..224cecca84 100644 --- a/lib/mixins/property-accessors.html +++ b/lib/mixins/property-accessors.html @@ -157,6 +157,26 @@ } } + /** + * Returns a property name that corresponds to the given attribute. + * By default, converts dash to camel case, e.g. `foo-bar` to `fooBar`. + * @param {string} attribute Attribute to convert + * @return {string} Property name corresponding to the given attribute. + */ + _propertyNameForAttribute(attribute) { + return caseMap.dashToCamelCase(attribute); + } + + /** + * Returns an attribute name that corresponds to the given property. + * By default, converts camel to dash case, e.g. `fooBar` to `foo-bar`. + * @param {string} property Property to convert + * @return {string} Attribute name corresponding to the given property. + */ + _attributeNameForProperty(property) { + return caseMap.camelToDashCase(property); + } + /** * Initializes the local storage for property accessors. * @@ -245,7 +265,7 @@ _attributeToProperty(attribute, value, type) { // Don't deserialize back to property if currently reflecting if (!this.__serializing) { - let property = caseMap.dashToCamelCase(attribute); + let property = this._propertyNameForAttribute(attribute); this[property] = this._deserializeValue(value, type); } } @@ -261,7 +281,7 @@ this.__serializing = true; value = (arguments.length < 3) ? this[property] : value; this._valueToNodeAttribute(this, value, - attribute || caseMap.camelToDashCase(property)); + attribute || this._attributeNameForProperty(property)); this.__serializing = false; } diff --git a/test/unit/polymer.basic-element.html b/test/unit/polymer.basic-element.html new file mode 100644 index 0000000000..d4655c213f --- /dev/null +++ b/test/unit/polymer.basic-element.html @@ -0,0 +1,360 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +