Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework component update logic avoiding memory allocations #5474

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/core/a-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
var ANode = require('./a-node').ANode;
var components = require('./component').components;
var utils = require('../utils');
var styleParser = utils.styleParser;

var MULTIPLE_COMPONENT_DELIMITER = '__';

Expand Down Expand Up @@ -65,9 +66,32 @@ class AMixin extends ANode {
if (value === undefined) {
value = window.HTMLElement.prototype.getAttribute.call(this, attr);
}

this.rawAttributeCache[attr] = value;
if (!component) { return; }
this.componentCache[attr] = component.parseAttrValueForCache(value);
this.componentCache[attr] = this.parseComponentAttrValue(component, value);
}

/**
* Given an HTML attribute value parses the string based on the component schema.
* To avoid double parsing of strings when mixed into the actual component,
* we store the original instead of the parsed one.
*
* @param {object} component - The component to parse for.
* @param {string} attrValue - HTML attribute value.
*/
parseComponentAttrValue (component, attrValue) {
var parsedValue;
if (typeof attrValue !== 'string') { return attrValue; }
if (component.isSingleProperty) {
parsedValue = component.schema.parse(attrValue);
if (typeof parsedValue === 'string') { parsedValue = attrValue; }
} else {
// Use style parser as the values will be parsed once mixed in.
// Furthermore parsing might fail with dynamic schema's.
parsedValue = styleParser.parse(attrValue);
}
return parsedValue;
}

/**
Expand Down
Loading
Loading