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

fix: order slots in state as in Light DOM #874

Merged
merged 4 commits into from
Oct 22, 2019
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
18 changes: 15 additions & 3 deletions packages/base/src/UI5Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ class UI5Element extends HTMLElement {
}

const autoIncrementMap = new Map();
const allChildrenUpgraded = domChildren.map(async child => {
const slottedChildrenMap = new Map();

const allChildrenUpgraded = domChildren.map(async (child, idx) => {
// Determine the type of the child (mainly by the slot attribute)
const slotName = this.constructor._getSlotName(child);
const slotData = slotsMap[slotName];
Expand Down Expand Up @@ -192,12 +194,22 @@ class UI5Element extends HTMLElement {
this._attachChildPropertyUpdated(child, slotData);
}

// Distribute the child in the _state object
const propertyName = slotData.propertyName || slotName;
this._state[propertyName].push(child);

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, slot) => {
this._state[slot] = children.sort((a, b) => a.idx - b.idx).map(_ => _.child);
});
this._invalidate();
}

Expand Down