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) {
reapplyFilter();
}
debounce(sorter().updateSort);
sorter().updateSort();
}

View File

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

View File

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

View File

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