|
2 | 2 | var ANode = require('./a-node').ANode; |
3 | 3 | var components = require('./component').components; |
4 | 4 | var utils = require('../utils'); |
| 5 | +var styleParser = utils.styleParser; |
5 | 6 |
|
6 | 7 | var MULTIPLE_COMPONENT_DELIMITER = '__'; |
7 | 8 |
|
@@ -65,9 +66,32 @@ class AMixin extends ANode { |
65 | 66 | if (value === undefined) { |
66 | 67 | value = window.HTMLElement.prototype.getAttribute.call(this, attr); |
67 | 68 | } |
| 69 | + |
68 | 70 | this.rawAttributeCache[attr] = value; |
69 | 71 | if (!component) { return; } |
70 | | - this.componentCache[attr] = component.parseAttrValueForCache(value); |
| 72 | + this.componentCache[attr] = this.parseComponentAttrValue(component, value); |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Given an HTML attribute value parses the string based on the component schema. |
| 77 | + * To avoid double parsing of strings when mixed into the actual component, |
| 78 | + * we store the original instead of the parsed one. |
| 79 | + * |
| 80 | + * @param {object} component - The component to parse for. |
| 81 | + * @param {string} attrValue - HTML attribute value. |
| 82 | + */ |
| 83 | + parseComponentAttrValue (component, attrValue) { |
| 84 | + var parsedValue; |
| 85 | + if (typeof attrValue !== 'string') { return attrValue; } |
| 86 | + if (component.isSingleProperty) { |
| 87 | + parsedValue = component.schema.parse(attrValue); |
| 88 | + if (typeof parsedValue === 'string') { parsedValue = attrValue; } |
| 89 | + } else { |
| 90 | + // Use style parser as the values will be parsed once mixed in. |
| 91 | + // Furthermore parsing might fail with dynamic schema's. |
| 92 | + parsedValue = styleParser.parse(attrValue); |
| 93 | + } |
| 94 | + return parsedValue; |
71 | 95 | } |
72 | 96 |
|
73 | 97 | /** |
|
0 commit comments