Skip to content

Commit

Permalink
refactor: rename folder
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Feb 23, 2024
1 parent 8d45669 commit 51f42f6
Show file tree
Hide file tree
Showing 27 changed files with 40 additions and 33 deletions.
2 changes: 1 addition & 1 deletion docs/rfcs/data-loaders/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ outline: 'deep'
- Target Major Version: Vue 3, Vue Router 4
- Reference Issues: -
- [Discussion](https://github.com/vuejs/rfcs/discussions/460)
- [Implementation PR](https://github.com/posva/unplugin-vue-router/tree/main/src/data-fetching)
- [Implementation PR](https://github.com/posva/unplugin-vue-router/tree/main/src/data-loaders)

## Todo List

Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,21 @@
"require": "./dist/types.js",
"import": "./dist/types.mjs"
},
"./data-fetching/entries/basic": {
"./data-loaders/basic": {
"types": {
"require": "./dist/data-fetching/entries/basic.d.ts",
"import": "./dist/data-fetching/entries/basic.d.mts"
"require": "./dist/data-loaders/basic.d.ts",
"import": "./dist/data-loaders/basic.d.mts"
},
"require": "./dist/data-fetching/entries/basic.js",
"import": "./dist/data-fetching/entries/basic.mjs"
"require": "./dist/data-loaders/basic.js",
"import": "./dist/data-loaders/basic.mjs"
},
"./data-fetching/entries/pinia-colada": {
"./data-loaders/pinia-colada": {
"types": {
"require": "./dist/data-fetching/entries/pinia-colada.d.ts",
"import": "./dist/data-fetching/entries/pinia-colada.d.mts"
"require": "./dist/data-loaders/pinia-colada.d.ts",
"import": "./dist/data-loaders/pinia-colada.d.mts"
},
"require": "./dist/data-fetching/entries/pinia-colada.js",
"import": "./dist/data-fetching/entries/pinia-colada.mjs"
"require": "./dist/data-loaders/pinia-colada.js",
"import": "./dist/data-loaders/pinia-colada.mjs"
},
"./client": {
"types": "./client.d.ts"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type {
DefineDataColadaLoaderOptions,
UseDataLoaderColada,
UseDataLoaderColadaResult,
} from '../defineColadaLoader.ts'
} from '../defineColadaLoader'
export type {
UseDataLoader,
UseDataLoaderInternals,
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ describe('navigation-guard', () => {
const loader1 = defineBasicLoader(async () => {})
const loader2 = defineBasicLoader(async () => {})
const loader3 = defineBasicLoader(async () => {})
const loader4 = defineBasicLoader(async () => {})
const loader5 = defineBasicLoader(async () => {})

it('creates a set of loaders during navigation', async () => {
const router = getRouter()
Expand Down Expand Up @@ -249,8 +247,7 @@ describe('navigation-guard', () => {
},
})

const p = router.push('/fetch')
await vi.runAllTimersAsync()
await router.push('/fetch')
expect(router.currentRoute.value.path).toBe('/fetch')
expect(l1.spy).not.toHaveBeenCalled()
expect(l2.spy).not.toHaveBeenCalled()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,9 @@ export function setupLoaderGuard({
const entry = loader._.getEntry(router as Router)
// lazy loaders do not block the navigation so the navigation guard
// might call commit before the loader is ready
if (!lazy || !entry.isLoading.value) {
loader._.getEntry(router as Router).commit(
to as RouteLocationNormalizedLoaded
)
// on the server, entries might not even exist
if (entry && (!lazy || !entry.isLoading.value)) {
entry.commit(to as RouteLocationNormalizedLoaded)
}
}
}
Expand All @@ -245,6 +244,8 @@ export function setupLoaderGuard({
return () => {
// @ts-expect-error: must be there in practice
delete router[LOADER_ENTRIES_KEY]
// @ts-expect-error: must be there in practice
delete router[APP_KEY]
removeLoaderGuard()
removeDataLoaderGuard()
removeAfterEach()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ export type {
DefineDataLoaderOptionsBase,
DefineLoaderFn,
_DataMaybeLazy,
} from './data-fetching/createDataLoader'
} from './data-loaders/createDataLoader'

// new data fetching
export {
DataLoaderPlugin,
NavigationResult,
} from './data-fetching/navigation-guard'
} from './data-loaders/navigation-guard'
export type {
DataLoaderPluginOptions,
SetupLoaderGuardOptions,
_DataLoaderRedirectResult,
} from './data-fetching/navigation-guard'
} from './data-loaders/navigation-guard'

// NOTE: for tests only
// export * from './data-fetching/defineQueryLoader'
// export * from './data-loaders/defineQueryLoader'

/**
* Defines properties of the route for the current page component.
Expand Down
2 changes: 1 addition & 1 deletion tests/data-loaders/loaders.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { vi } from 'vitest'
import { defineBasicLoader } from '../../src/data-fetching/defineLoader'
import { defineBasicLoader } from '../../src/data-loaders/defineLoader'

export const dataOneSpy = vi.fn(async () => 'resolved 1')
export const dataTwoSpy = vi.fn(async () => 'resolved 2')
Expand Down
6 changes: 3 additions & 3 deletions tests/data-loaders/tester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import { type App, defineComponent, inject, type Plugin } from 'vue'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { mount } from '@vue/test-utils'
import { getRouter } from 'vue-router-mock'
import { setCurrentContext } from '../../src/data-fetching/utils'
import { setCurrentContext } from '../../src/data-loaders/utils'
import {
DataLoaderPlugin,
NavigationResult,
type DataLoaderPluginOptions,
} from '../../src/data-fetching/navigation-guard'
} from '../../src/data-loaders/navigation-guard'
import type {
DataLoaderContextBase,
DefineDataLoaderOptionsBase,
UseDataLoader,
} from '../../src/data-fetching/createDataLoader'
} from '../../src/data-loaders/createDataLoader'
import { mockPromise } from '../utils'
import RouterViewMock from '../data-loaders/RouterViewMock.vue'
import ComponentWithNestedLoader from '../data-loaders/ComponentWithNestedLoader.vue'
Expand Down
4 changes: 2 additions & 2 deletions tests/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { vi } from 'vitest'
import type { NavigationResult } from '../src/data-fetching/navigation-guard'
import type { NavigationResult } from '../src/data-loaders/navigation-guard'
import {
type DefineDataLoaderOptions,
defineBasicLoader,
} from '../src/data-fetching/defineLoader'
} from '../src/data-loaders/defineLoader'

export const delay = (ms: number) =>
new Promise((resolve) => setTimeout(resolve, ms))
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"exclude": [
"./src/**/*.test-d.ts",
// "./src/**/*.spec.ts",
// "./src/data-fetching/defineQueryLoader.ts",
// "./src/data-fetching/defineVueFireLoader.ts",
// "./src/data-loaders/defineQueryLoader.ts",
// "./src/data-loaders/defineVueFireLoader.ts",
"node_modules",
"dist"
],
Expand Down
11 changes: 10 additions & 1 deletion tsup-runtime.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ export default defineConfig([
{
...commonOptions,
clean: false,
entry: ['./src/runtime.ts', './src/data-fetching/entries/*'],
entry: ['./src/runtime.ts'],
external: [...commonOptions.external, 'unplugin-vue-router/types'],
},

{
...commonOptions,
clean: false,
entry: ['./src/data-loaders/entries/*'],
// to work with node10 moduleResolution mode
outDir: 'dist/data-loaders',
external: [...commonOptions.external, 'unplugin-vue-router/types'],
},
])

0 comments on commit 51f42f6

Please sign in to comment.