Fix updateSort

This commit is contained in:
Rob Garrison 2017-12-23 21:42:57 -06:00
parent b520e73c99
commit cedf2fd691
4 changed files with 15 additions and 26 deletions

View File

@ -156,7 +156,7 @@ function filterOnChange({target: el, forceRefilter}) {
if (installed) { if (installed) {
reapplyFilter(); reapplyFilter();
} }
debounce(sorter().updateSort); sorter().updateSort();
} }

View File

@ -459,7 +459,7 @@ function handleUpdate(style, {reason, method} = {}) {
handleUpdateInstalled(entry, reason); handleUpdateInstalled(entry, reason);
} }
filterAndAppend({entry}); filterAndAppend({entry});
debounce(sorter().updateSort); sorter().updateSort();
if (!entry.matches('.hidden') && reason !== 'import') { if (!entry.matches('.hidden') && reason !== 'import') {
animateElement(entry); animateElement(entry);
scrollElementIntoView(entry); scrollElementIntoView(entry);

View File

@ -144,35 +144,24 @@ const sorter = (() => {
} }
function updateSort() { function updateSort() {
getStylesSafe().then(styles => {
const renderBin = document.createDocumentFragment(); const renderBin = document.createDocumentFragment();
const entries = sortStyles({parser: 'entry'}); const entries = sortStyles(styles);
const isDiffSort = [...installed.children].find((entry, index) => entry.id !== entries[index].id); const current = [...installed.children];
let index = 0; const isDiffSort = entries.length !== current.length ||
function moveEntries() { current.find((entry, index) => entry.id !== entries[index].id);
const t0 = performance.now(); if (isDiffSort) {
let moved = 0; entries.forEach(entry => renderBin.appendChild(entry));
while (
index < entries.length &&
(++moved < 10 || performance.now() - t0 < 10)
) {
renderBin.appendChild(entries[index++]);
}
if (index < entries.length) {
requestAnimationFrame(moveEntries);
return;
}
}
if (isDiffSort !== undefined) {
moveEntries();
installed.appendChild(renderBin); installed.appendChild(renderBin);
updateStripes(); updateStripes();
} }
});
} }
function manageSort(event) { function manageSort(event) {
event.preventDefault(); event.preventDefault();
prefs.set('manage.newUI.sort', this.value); prefs.set('manage.newUI.sort', this.value);
debounce(updateSort); updateSort();
} }
function showSortHelp(event) { function showSortHelp(event) {

View File

@ -144,7 +144,7 @@ function reportUpdateState(state, style, details) {
} }
if (filtersSelector.hide) { if (filtersSelector.hide) {
filterAndAppend({entry}); filterAndAppend({entry});
debounce(sorter().updateSort); sorter().updateSort();
} }
} }