Skip to content

Commit 80c7a19

Browse files
committed
Rework component update logic avoiding memory allocations
1 parent af4523e commit 80c7a19

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

@@ -65,9 +66,32 @@ class AMixin extends ANode {
6566
if (value === undefined) {
6667
value = window.HTMLElement.prototype.getAttribute.call(this, attr);
6768
}
69+
6870
this.rawAttributeCache[attr] = value;
6971
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;
7195
}
7296

7397
/**

0 commit comments

Comments
 (0)