|
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 |
|
@@ -55,9 +56,32 @@ class AMixin extends ANode { |
55 | 56 | if (value === undefined) { |
56 | 57 | value = window.HTMLElement.prototype.getAttribute.call(this, attr); |
57 | 58 | } |
| 59 | + |
58 | 60 | this.rawAttributeCache[attr] = value; |
59 | 61 | if (!component) { return; } |
60 | | - this.componentCache[attr] = component.parseAttrValueForCache(value); |
| 62 | + this.componentCache[attr] = this.parseComponentAttrValue(component, value); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Given an HTML attribute value parses the string based on the component schema. |
| 67 | + * To avoid double parsing of strings when mixed into the actual component, |
| 68 | + * we store the original instead of the parsed one. |
| 69 | + * |
| 70 | + * @param {object} component - The component to parse for. |
| 71 | + * @param {string} attrValue - HTML attribute value. |
| 72 | + */ |
| 73 | + parseComponentAttrValue (component, attrValue) { |
| 74 | + var parsedValue; |
| 75 | + if (typeof attrValue !== 'string') { return attrValue; } |
| 76 | + if (component.isSingleProperty) { |
| 77 | + parsedValue = component.schema.parse(attrValue); |
| 78 | + if (typeof parsedValue === 'string') { parsedValue = attrValue; } |
| 79 | + } else { |
| 80 | + // Use style parser as the values will be parsed once mixed in. |
| 81 | + // Furthermore parsing might fail with dynamic schema's. |
| 82 | + parsedValue = styleParser.parse(attrValue); |
| 83 | + } |
| 84 | + return parsedValue; |
61 | 85 | } |
62 | 86 |
|
63 | 87 | /** |
|
0 commit comments