Skip to content

Commit 0163811

Browse files
committed
feat(loaders): add more state to pinia colada
1 parent 0903d61 commit 0163811

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

playground/src/pages/users/colada-loader.[id].vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const {
2626
status,
2727
error,
2828
isLoading,
29+
asyncStatus,
2930
reload,
3031
refresh,
3132
} = useUserData()
@@ -62,6 +63,8 @@ const {
6263

6364
<p>
6465
<code>status: {{ status }}</code>
66+
|
67+
<code>asyncStatus: {{ asyncStatus }}</code>
6568
<br />
6669
<code>isFetching: {{ isLoading }}</code>
6770
</p>

src/data-loaders/defineColadaLoader.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ import { toLazyValue } from './createDataLoader'
4747
* Creates a data loader composable that can be exported by pages to attach the data loading to a route. This returns a
4848
* composable that can be used in any component.
4949
*
50+
* The returned composable exposes a mix of Data Loaders state and Pinia
51+
* Colada state.
52+
* - `data`, `isLoading`, `error` are navigation dependent and follow data loaders behavior.
53+
* - `status`, `asyncStatus`, `state` are Pinia Colada state and will immediately change and reflect the state of the
54+
* query.
55+
*
5056
* @experimental
5157
* Still under development and subject to change. See https://github.com/vuejs/rfcs/discussions/460
5258
*
@@ -383,7 +389,7 @@ export function defineColadaLoader<Data, isLazy extends boolean>(
383389

384390
const { data, error, isLoading, ext } = entry
385391

386-
// TODO: add watchers only once
392+
// TODO: add watchers only once alongside the entry
387393
// update the data when pinia colada updates it e.g. after visibility change
388394
watch(ext!.data, (newData) => {
389395
// only if we are not in the middle of a navigation
@@ -425,8 +431,10 @@ export function defineColadaLoader<Data, isLazy extends boolean>(
425431
router[APP_KEY].runWithContext(() => load(to, router)).then(
426432
() => (entry!.commit(to), entry.ext!.state.value)
427433
),
428-
isPending: ext!.isPending,
429434
status: ext!.status,
435+
asyncStatus: ext!.asyncStatus,
436+
state: ext!.state,
437+
isPending: ext!.isPending,
430438
} satisfies UseDataLoaderColadaResult<boolean, unknown>
431439

432440
// load ensures there is a pending load
@@ -496,7 +504,7 @@ export interface UseDataLoaderColadaResult<isLazy extends boolean, Data>
496504
extends UseDataLoaderResult<isLazy, Data>,
497505
Pick<
498506
UseQueryReturn<Data, any>,
499-
'isPending' | 'refetch' | 'refresh' | 'status'
507+
'isPending' | 'refetch' | 'refresh' | 'status' | 'asyncStatus' | 'state'
500508
> {}
501509

502510
/**

0 commit comments

Comments
 (0)