Skip to content

Commit

Permalink
In optimizeComponents be sure to also remove components that are defi…
Browse files Browse the repository at this point in the history
…ned in the primitive with empty object (#780)

* In optimizeComponents be sure to also remove components that are defined in the primitive with empty object

* Use component.attrName that includes the name plus optional id like event-set__click when checking for implicit value (from mixin or primitive)
  • Loading branch information
vincentfretin authored Nov 27, 2024
1 parent b36db04 commit a2aefc8
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/lib/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@ function getImplicitValue(component, source) {
function _multi() {
var value;

// Set isInherited to true if the component is inherited from primitive defaultComponents and is empty object
var defaults = source.defaultComponentsFromPrimitive;
isInherited =
defaults &&
/* eslint-disable-next-line no-prototype-builtins */
defaults.hasOwnProperty(component.attrName) &&
Object.keys(defaults[component.attrName]).length === 0;
Object.keys(component.schema).forEach(function (propertyName) {
var propertyValue = getFromAttribute(component, propertyName, source);
if (propertyValue === undefined) {
Expand Down Expand Up @@ -362,15 +369,15 @@ function getFromAttribute(component, propertyName, source) {
*/
function getMixedValue(component, propertyName, source) {
var value;
var reversedMixins = source.mixinEls.reverse();
var reversedMixins = source.mixinEls.toReversed();
for (var i = 0; value === undefined && i < reversedMixins.length; i++) {
var mixin = reversedMixins[i];
/* eslint-disable-next-line no-prototype-builtins */
if (mixin.attributes.hasOwnProperty(component.name)) {
if (mixin.attributes.hasOwnProperty(component.attrName)) {
if (!propertyName) {
value = mixin.getAttribute(component.name);
value = mixin.getAttribute(component.attrName);
} else {
value = mixin.getAttribute(component.name)[propertyName];
value = mixin.getAttribute(component.attrName)[propertyName];
}
}
}
Expand All @@ -379,7 +386,7 @@ function getMixedValue(component, propertyName, source) {

/**
* Gets the value for a component or component's property coming from primitive
* defaults or a-frame defaults. In this specific order.
* defaults.
*
* @param {Component} component Component to be found.
* @param {string} [propertyName] If provided, component's property to be
Expand All @@ -390,18 +397,16 @@ function getMixedValue(component, propertyName, source) {
*/
function getInjectedValue(component, propertyName, source) {
var value;
var primitiveDefaults = source.defaultComponentsFromPrimitive || {};
var aFrameDefaults = source.defaultComponents || {};
var defaultSources = [primitiveDefaults, aFrameDefaults];
for (var i = 0; value === undefined && i < defaultSources.length; i++) {
var defaults = defaultSources[i];
var primitiveDefaults = source.defaultComponentsFromPrimitive;
if (
primitiveDefaults &&
/* eslint-disable-next-line no-prototype-builtins */
if (defaults.hasOwnProperty(component.name)) {
if (!propertyName) {
value = defaults[component.name];
} else {
value = defaults[component.name][propertyName];
}
primitiveDefaults.hasOwnProperty(component.attrName)
) {
if (!propertyName) {
value = primitiveDefaults[component.attrName];
} else {
value = primitiveDefaults[component.attrName][propertyName];
}
}
return value;
Expand Down

0 comments on commit a2aefc8

Please sign in to comment.