Skip to content

Commit

Permalink
fix: upgrade support for pinia colada 0.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Nov 29, 2024
1 parent e61d071 commit b01dce4
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 37 deletions.
4 changes: 2 additions & 2 deletions examples/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"preview": "nuxt preview"
},
"devDependencies": {
"@pinia/nuxt": "^0.7.0",
"@pinia/nuxt": "^0.8.0",
"nuxt": "^3.14.1592",
"unplugin-vue-router": "workspace:*"
},
"dependencies": {
"@pinia/colada": "^0.12.1",
"@pinia/colada": "^0.13.0",
"pinia": "^2.2.8"
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
}
},
"devDependencies": {
"@pinia/colada": "^0.12.1",
"@pinia/colada": "^0.13.0",
"@shikijs/vitepress-twoslash": "1.23.1",
"@tanstack/vue-query": "^5.60.6",
"@types/node": "^22.10.1",
Expand All @@ -209,7 +209,7 @@
"nodemon": "^3.1.7",
"p-series": "^3.0.0",
"pinia": "^2.2.8",
"prettier": "^3.3.3",
"prettier": "^3.4.1",
"rimraf": "^6.0.1",
"rollup": "^4.27.4",
"semver": "^7.6.3",
Expand Down
39 changes: 19 additions & 20 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions src/data-loaders/createDataLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ import { ErrorDefault } from './types-config'
/**
* Base type for a data loader entry. Each Data Loader has its own entry in the `loaderEntries` (accessible via `[LOADER_ENTRIES_KEY]`) map.
*/
export interface DataLoaderEntryBase<Data = unknown, TError = unknown> {
export interface DataLoaderEntryBase<
TData = unknown,
TError = unknown,
// TODO: technically we could just make loaders pass TData | undefined as the first type parameter
// this requires quite some code updates, this version is retro-compatible
TDataInitial extends TData | undefined = TData | undefined,
> {
/**
* Data stored in the entry.
*/
data: ShallowRef<Data | undefined>
data: ShallowRef<TData | TDataInitial>

/**
* Error if there was an error.
Expand Down Expand Up @@ -51,7 +57,7 @@ export interface DataLoaderEntryBase<Data = unknown, TError = unknown> {
* Data that was staged by a loader. This is used to avoid showing the old data while the new data is loading. Calling
* the internal `commit()` function will replace the data with the staged data.
*/
staged: Data | typeof STAGED_NO_VALUE
staged: TData | typeof STAGED_NO_VALUE

/**
* Error that was staged by a loader. This is used to avoid showing the old error while the new data is loading.
Expand Down Expand Up @@ -272,11 +278,11 @@ export interface UseDataLoaderInternals<Data = unknown, TError = unknown> {
/**
* Return value of a loader composable defined with `defineLoader()`.
*/
export interface UseDataLoaderResult<Data = unknown, TError = ErrorDefault> {
export interface UseDataLoaderResult<TData = unknown, TError = ErrorDefault> {
/**
* Data returned by the loader. If the data loader is lazy, it will be undefined until the first load.
*/
data: ShallowRef<Data>
data: ShallowRef<TData>

/**
* Whether there is an ongoing request.
Expand Down
22 changes: 14 additions & 8 deletions src/data-loaders/defineColadaLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,21 +562,24 @@ export type DefineDataColadaLoaderOptions<
*/
export interface DataColadaLoaderContext extends DataLoaderContextBase {}

export interface UseDataLoaderColadaResult<Data>
extends UseDataLoaderResult<Data, ErrorDefault>,
export interface UseDataLoaderColadaResult<
TData,
TError = ErrorDefault,
TDataInitial extends TData | undefined = TData | undefined,
> extends UseDataLoaderResult<TData | TDataInitial, ErrorDefault>,
Pick<
UseQueryReturn<Data, any>,
UseQueryReturn<TData, TError, TDataInitial>,
'isPending' | 'status' | 'asyncStatus' | 'state'
> {
refetch: (
to?: RouteLocationNormalizedLoaded
// TODO: we might need to add this in the future
// ...coladaArgs: Parameters<UseQueryReturn<Data, any>['refresh']>
) => ReturnType<UseQueryReturn<Data, any>['refetch']>
) => ReturnType<UseQueryReturn<TData, TError, TDataInitial>['refetch']>

refresh: (
to?: RouteLocationNormalizedLoaded
) => ReturnType<UseQueryReturn<Data, any>['refetch']>
) => ReturnType<UseQueryReturn<TData, TError, TDataInitial>['refetch']>
}

/**
Expand Down Expand Up @@ -649,8 +652,11 @@ export interface UseDataLoaderColada_DefinedData<Data>
>
}

export interface DataLoaderColadaEntry<Data, TError = unknown>
extends DataLoaderEntryBase<Data, TError> {
export interface DataLoaderColadaEntry<
TData,
TError = unknown,
TDataInitial extends TData | undefined = TData | undefined,
> extends DataLoaderEntryBase<TData, TError, TDataInitial> {
/**
* Reactive route passed to pinia colada so it automatically refetch
*/
Expand All @@ -664,7 +670,7 @@ export interface DataLoaderColadaEntry<Data, TError = unknown>
/**
* Extended options for pinia colada
*/
ext: UseQueryReturn<Data, TError> | null
ext: UseQueryReturn<TData, TError, TDataInitial> | null
}

interface TrackedRoute {
Expand Down

0 comments on commit b01dce4

Please sign in to comment.