Skip to content

Commit

Permalink
⚡ Add response caching in states for better performances
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed Jun 17, 2024
1 parent c6830c8 commit a7568dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions components/webtoons/episodes/EpisodeList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ const maxIndex = ref<number>(30);
const id = useRoute().params.id as any as number;
function loadEpisodes(){
const webtoonState: any = useState(`webtoon-${id}`);
if (webtoonState.value){
episodes.value = webtoonState.value;
return;
}
getEpisodes(id).then(response => {
episodes.value = response.data;
webtoonState.value = response.data;
});
}
Expand Down
6 changes: 6 additions & 0 deletions components/webtoons/webtoons/WebtoonList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ function increaseMaxIndex(){
}
onMounted(async() => {
const webtoonsState: any = useState("webtoons");
if (webtoonsState.value && webtoonsState.value.length){
webtoons.value = webtoonsState.value;
return;
}
const response = await getWebtoons();
webtoons.value = response.data;
// Sort webtoons by title
Expand All @@ -26,6 +31,7 @@ onMounted(async() => {
webtoons.value.sort((a, b) => b.hasNewEpisodes - a.hasNewEpisodes);
// Then by isNew
webtoons.value.sort((a, b) => b.isNew - a.isNew);
webtoonsState.value = webtoons.value;
});
// Computed property for filtered webtoons
Expand Down

0 comments on commit a7568dd

Please sign in to comment.