Skip to content
Merged
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
43 changes: 27 additions & 16 deletions packages/base/src/UI5Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ abstract class UI5Element extends HTMLElement {
const autoIncrementMap = new Map<string, number>();
const slottedChildrenMap = new Map<string, Array<{ child: Node, idx: number }>>();

const allChildrenUpgraded = domChildren.map(async (child, idx) => {
domChildren.forEach((child, idx) => {
// Determine the type of the child (mainly by the slot attribute)
const slotName = getSlotName(child);
const slotData = slotsMap[slotName];
Expand All @@ -474,6 +474,32 @@ abstract class UI5Element extends HTMLElement {
return;
}

const propertyName = slotData.propertyName || slotName;

if (slottedChildrenMap.has(propertyName)) {
slottedChildrenMap.get(propertyName)!.push({ child, idx });
} else {
slottedChildrenMap.set(propertyName, [{ child, idx }]);
}
});

// Distribute the child in the _state object, keeping the Light DOM order,
// not the order elements are defined.
slottedChildrenMap.forEach((children, propertyName) => {
this._state[propertyName] = children.sort((a, b) => a.idx - b.idx).map(_ => _.child);
this._state[kebabToCamelCase(propertyName)] = this._state[propertyName];
});

const allChildrenUpgraded = domChildren.map(async child => {
// Determine the type of the child (mainly by the slot attribute)
const slotName = getSlotName(child);
const slotData = slotsMap[slotName];

// Check if the slotName is supported
if (slotData === undefined) {
return;
}

// For children that need individual slots, calculate them
if (slotData.individualSlots) {
const nextIndex = (autoIncrementMap.get(slotName) || 0) + 1;
Expand Down Expand Up @@ -513,25 +539,10 @@ abstract class UI5Element extends HTMLElement {
if (child instanceof HTMLSlotElement) {
this._attachSlotChange(child, slotName, !!slotData.invalidateOnChildChange);
}

const propertyName = slotData.propertyName || slotName;

if (slottedChildrenMap.has(propertyName)) {
slottedChildrenMap.get(propertyName)!.push({ child, idx });
} else {
slottedChildrenMap.set(propertyName, [{ child, idx }]);
}
});

await Promise.all(allChildrenUpgraded);

// Distribute the child in the _state object, keeping the Light DOM order,
// not the order elements are defined.
slottedChildrenMap.forEach((children, propertyName) => {
this._state[propertyName] = children.sort((a, b) => a.idx - b.idx).map(_ => _.child);
this._state[kebabToCamelCase(propertyName)] = this._state[propertyName];
});

// Compare the content of each slot with the cached values and invalidate for the ones that changed
let invalidated = false;
for (const [slotName, slotData] of Object.entries(slotsMap)) { // eslint-disable-line
Expand Down
Loading