Fix updateSort part deux

This commit is contained in:
Rob Garrison 2017-12-23 22:22:39 -06:00
parent cedf2fd691
commit 5eeb0c82ea
2 changed files with 17 additions and 12 deletions

View File

@ -155,9 +155,9 @@ function filterOnChange({target: el, forceRefilter}) {
}); });
if (installed) { if (installed) {
reapplyFilter(); reapplyFilter();
}
sorter().updateSort(); sorter().updateSort();
} }
}
function filterAndAppend({entry, container}) { function filterAndAppend({entry, container}) {

View File

@ -144,18 +144,23 @@ const sorter = (() => {
} }
function updateSort() { function updateSort() {
getStylesSafe().then(styles => { if (!installed) return;
const renderBin = document.createDocumentFragment();
const entries = sortStyles(styles);
const current = [...installed.children]; const current = [...installed.children];
const isDiffSort = entries.length !== current.length || const sorted = sortStyles({
current.find((entry, index) => entry.id !== entries[index].id); styles: current.map(entry => ({
entry,
name: entry.styleNameLowerCase,
style: BG.cachedStyles.byId.get(entry.styleId),
}))
});
const isDiffSort = sorted.length !== current.length ||
current.find((entry, index) => entry !== sorted[index].entry);
if (isDiffSort) { if (isDiffSort) {
entries.forEach(entry => renderBin.appendChild(entry)); const renderBin = document.createDocumentFragment();
sorted.forEach(({entry}) => renderBin.appendChild(entry));
installed.appendChild(renderBin); installed.appendChild(renderBin);
updateStripes(); updateStripes();
} }
});
} }
function manageSort(event) { function manageSort(event) {