Skip to content

Commit

Permalink
Merge pull request #255 from Suwayomi/main
Browse files Browse the repository at this point in the history
loading chapter drawer performance
  • Loading branch information
Robonau authored Dec 14, 2024
2 parents 60af49c + 2c38cdb commit 25ab56e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 21 deletions.
51 changes: 34 additions & 17 deletions src/lib/simpleStores.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ class GMState {
this.store.value = this.extractGlobalMeta(queryResult);
this.fixOldTriStates();
if (queryResult.fetching) return;
this.traverse(this.store.value, trueDefaults);
this.unSub();
});
$effect(() => {
Expand Down Expand Up @@ -317,17 +318,22 @@ class GMState {
}

private traverse<T extends Record<string, unknown>>(value: T, defaults: T) {
getObjectKeys(value).forEach((key) => {
if (value[key] === undefined) {
value[key] = defaults[key];
}
if (this.isRecord(value[key]) && this.isRecord(defaults[key]))
this.traverse(value[key], defaults[key]);
});
const vals: [Record<string, unknown>, Record<string, unknown>][] = [
[value, defaults]
];
while (vals.length > 0) {
const [valu, defaulte] = vals.shift()!;
Object.keys(value).forEach((key: keyof Record<string, unknown>) => {
if (valu[key] === undefined) {
valu[key] = defaulte[key];
}
if (this.isRecord(valu[key]) && this.isRecord(defaulte[key]))
vals.push([valu[key], defaulte[key]]);
});
}
}

get value() {
this.traverse(this.store.value, trueDefaults);
return this.store.value;
}

Expand Down Expand Up @@ -372,6 +378,7 @@ class MMState {
const metaKey = metaKeyBase + key;
const storedValue = untrack(() => {
if (!this.MMeta) return;
this.traverse(this.store, gmState.value.mangaMetaDefaults);
return get(this.MMeta).data?.manga?.meta.find(
(e) => e.key === metaKey
)?.value;
Expand Down Expand Up @@ -412,18 +419,28 @@ class MMState {
return obj === Object(obj);
}

private traverse<T extends Record<string, unknown>>(value: T, defaults: T) {
getObjectKeys(value).forEach((key) => {
if (value[key] === undefined) {
value[key] = defaults[key];
}
if (this.isRecord(value[key]) && this.isRecord(defaults[key]))
this.traverse(value[key], defaults[key]);
});
private traverse(
value: Record<string, unknown>,
defaults: Record<string, unknown>
) {
const val2 = $state.snapshot(value);
const vals: [Record<string, unknown>, Record<string, unknown>][] = [
[val2, defaults]
];
while (vals.length > 0) {
const [valu, defaulte] = vals.shift()!;
Object.keys(value).forEach((key: keyof Record<string, unknown>) => {
if (valu[key] === undefined) {
valu[key] = defaulte[key];
}
if (this.isRecord(valu[key]) && this.isRecord(defaulte[key]))
vals.push([valu[key], defaulte[key]]);
});
}
value = val2;
}

get value() {
this.traverse(this.store, gmState.value.mangaMetaDefaults);
return this.store;
}

Expand Down
11 changes: 7 additions & 4 deletions src/routes/(app)/manga/[MangaID]/(manga)/chaptersSide.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,13 @@
let _scrollToChaps: HTMLDivElement[] = $state([]);
let scrollToChaps: HTMLDivElement | undefined = $state();
let hash = $state(location.hash);
// @ts-ignore-next-line
navigation?.addEventListener('navigate', (event) => {
hash = new URL(event.destination.url).hash;
});
if ('navigation' in window) {
// @ts-ignore-next-line
window.navigation?.addEventListener('navigate', (event) => {
hash = new URL(event.destination.url).hash;
});
}
function handelScrollToChaps() {
let ind = _scrollToChaps.filter((e) => e).findIndex((e) => e.id === hash);
Expand Down

0 comments on commit 25ab56e

Please sign in to comment.