Skip to content

Commit db5c85d

Browse files
authored
Rework component update logic avoiding memory allocations (#5474)
Co-authored-by: Noeri Huisman <mrxz@users.noreply.github.com>
1 parent b40fc05 commit db5c85d

File tree

12 files changed

+496
-511
lines changed

12 files changed

+496
-511
lines changed

src/core/a-mixin.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
var ANode = require('./a-node').ANode;
33
var components = require('./component').components;
44
var utils = require('../utils');
5+
var styleParser = utils.styleParser;
56

67
var MULTIPLE_COMPONENT_DELIMITER = '__';
78

@@ -55,9 +56,32 @@ class AMixin extends ANode {
5556
if (value === undefined) {
5657
value = window.HTMLElement.prototype.getAttribute.call(this, attr);
5758
}
59+
5860
this.rawAttributeCache[attr] = value;
5961
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;
6185
}
6286

6387
/**

0 commit comments

Comments
 (0)