This repository has been archived by the owner on Apr 6, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nuxt): refresh override for data fetching composables (#7864)
- Loading branch information
Showing
7 changed files
with
74 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<template> | ||
<div> | ||
Override | ||
{{ data }} | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
let count = 0 | ||
let timeout = 0 | ||
const { data, refresh } = await useAsyncData(() => process.server ? Promise.resolve(1) : new Promise(resolve => setTimeout(() => resolve(++count), timeout))) | ||
if (count || data.value !== 1) { | ||
throw new Error('Data should be unset') | ||
} | ||
timeout = 100 | ||
const p = refresh() | ||
if (process.client && (count !== 0 || data.value !== 1)) { | ||
throw new Error('count should start at 0') | ||
} | ||
timeout = 0 | ||
await refresh({ override: true }) | ||
if (process.client && (count !== 1 || data.value !== 1)) { | ||
throw new Error('override should execute') | ||
} | ||
await p | ||
if (process.client && (count !== 2 || data.value !== 1)) { | ||
throw new Error('cancelled promise should not affect data') | ||
} | ||
</script> |