Merge branch 'dontusetoreverse' into 'develop'
dev: use reverse instead of toReversed Co-authored-by: Lhcfl <Lhcfl@outlook.com> See merge request firefish/firefish!10787
This commit is contained in:
commit
f85e6ebb19
1 changed files with 7 additions and 3 deletions
|
@ -173,11 +173,15 @@ const rootEl = ref<HTMLElement>();
|
||||||
const items = ref<Item[]>([]);
|
const items = ref<Item[]>([]);
|
||||||
const foldedItems = ref([]) as Ref<Fold[]>;
|
const foldedItems = ref([]) as Ref<Fold[]>;
|
||||||
|
|
||||||
|
function toReversed<T>(arr: T[]) {
|
||||||
|
return [...arr].reverse();
|
||||||
|
}
|
||||||
|
|
||||||
// To improve performance, we do not use vue’s `computed` here
|
// To improve performance, we do not use vue’s `computed` here
|
||||||
function calculateItems() {
|
function calculateItems() {
|
||||||
function getItems<T>(folder: (ns: Item[]) => T[]) {
|
function getItems<T>(folder: (ns: Item[]) => T[]) {
|
||||||
const res = [
|
const res = [
|
||||||
folder(prepended.value.toReversed()),
|
folder(toReversed(prepended.value)),
|
||||||
...arrItems.value.map((arr) => folder(arr)),
|
...arrItems.value.map((arr) => folder(arr)),
|
||||||
folder(appended.value),
|
folder(appended.value),
|
||||||
].flat(1);
|
].flat(1);
|
||||||
|
@ -351,7 +355,7 @@ async function fetch(firstFetching?: boolean) {
|
||||||
|
|
||||||
if (firstFetching && props.folder != null) {
|
if (firstFetching && props.folder != null) {
|
||||||
// In this way, prepended has some initial values for folding
|
// In this way, prepended has some initial values for folding
|
||||||
prepended.value = res.toReversed();
|
prepended.value = toReversed(res);
|
||||||
} else {
|
} else {
|
||||||
// For ascending and offset modes, append and prepend may cause item duplication
|
// For ascending and offset modes, append and prepend may cause item duplication
|
||||||
// so they need to be filtered out.
|
// so they need to be filtered out.
|
||||||
|
@ -398,7 +402,7 @@ const prepend = (...item: Item[]): void => {
|
||||||
prepended.value.length >
|
prepended.value.length >
|
||||||
(props.pagination.secondFetchLimit || SECOND_FETCH_LIMIT_DEFAULT)
|
(props.pagination.secondFetchLimit || SECOND_FETCH_LIMIT_DEFAULT)
|
||||||
) {
|
) {
|
||||||
arrItems.value.unshift(prepended.value.toReversed());
|
arrItems.value.unshift(toReversed(prepended.value));
|
||||||
prepended.value = [];
|
prepended.value = [];
|
||||||
// We don't need to calculate here because it won't cause any changes in items
|
// We don't need to calculate here because it won't cause any changes in items
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue