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() {
const renderBin = document.createDocumentFragment(); getStylesSafe().then(styles => {
const entries = sortStyles({parser: 'entry'}); const renderBin = document.createDocumentFragment();
const isDiffSort = [...installed.children].find((entry, index) => entry.id !== entries[index].id); const entries = sortStyles(styles);
let index = 0; const current = [...installed.children];
function moveEntries() { const isDiffSort = entries.length !== current.length ||
const t0 = performance.now(); current.find((entry, index) => entry.id !== entries[index].id);
let moved = 0; if (isDiffSort) {
while ( entries.forEach(entry => renderBin.appendChild(entry));
index < entries.length && installed.appendChild(renderBin);
(++moved < 10 || performance.now() - t0 < 10) updateStripes();
) {
renderBin.appendChild(entries[index++]);
} }
if (index < entries.length) { });
requestAnimationFrame(moveEntries);
return;
}
}
if (isDiffSort !== undefined) {
moveEntries();
installed.appendChild(renderBin);
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();
} }
} }