Skip to content

Commit

Permalink
refactor!: rename data fetching store
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Feb 6, 2024
1 parent 848682b commit b9ef0fb
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export {
export { QueryPlugin, type QueryPluginOptions } from './query-plugin'

export {
useDataFetchingStore,
useQueryCache,
type UseQueryStatus,
serialize,
type UseQueryEntry,
} from './data-fetching-store'
} from './query-store'

export { TreeMapNode, type EntryNodeKey } from './tree-map'

Expand Down
4 changes: 2 additions & 2 deletions src/query-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
UseQueryOptions,
UseQueryOptionsWithDefaults,
} from './query-options'
import { UseQueryEntry, useDataFetchingStore } from './data-fetching-store'
import { UseQueryEntry, useQueryCache } from './query-store'
import { _Simplify, noop } from './utils'
import type { UseQueryReturn } from './use-query'

Expand Down Expand Up @@ -52,7 +52,7 @@ export function QueryPlugin(
)
}

const store = useDataFetchingStore(pinia)
const store = useQueryCache(pinia)
store.$onAction(({ name, after, onError: _onError }) => {
// FIXME: refetch / refresh
if (name === 'refetch' || name === 'refresh') {
Expand Down
2 changes: 1 addition & 1 deletion src/data-fetching-store.ts → src/query-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const queryEntry_toString = <TResult, TError>(
*/
export const QUERY_STORE_ID = '_pc_query'

export const useDataFetchingStore = defineStore(QUERY_STORE_ID, () => {
export const useQueryCache = defineStore(QUERY_STORE_ID, () => {
const entryRegistry = shallowReactive(new TreeMapNode<UseQueryEntry>())

// FIXME: start from here: replace properties entry with a QueryEntry that is created when needed and contains all the needed part, included functions
Expand Down
2 changes: 1 addition & 1 deletion src/tree-serialize.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
createQueryEntry,
createTreeMap,
serialize,
} from './data-fetching-store'
} from './query-store'

describe('tree-map serialization', () => {
it('basic serialization', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/use-mutation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { computed, ref, type ComputedRef, shallowRef } from 'vue'
import { UseQueryStatus, useDataFetchingStore } from './data-fetching-store'
import { UseQueryStatus, useQueryCache } from './query-store'
import { type _MaybeArray, toArray } from './utils'
import { UseQueryKey } from './query-options'

Expand Down Expand Up @@ -71,7 +71,7 @@ export function useMutation<
>(
options: UseMutationOptions<TResult, TParams>
): UseMutationReturn<TResult, TParams, TError> {
const store = useDataFetchingStore()
const store = useQueryCache()

const status = shallowRef<UseQueryStatus>('pending')
const data = shallowRef<TResult>()
Expand Down
10 changes: 5 additions & 5 deletions src/use-query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import {
createQueryEntry,
createTreeMap,
serialize,
useDataFetchingStore,
} from './data-fetching-store'
useQueryCache,
} from './query-store'
import { TreeMapNode, entryNodeSize } from './tree-map'
import { UseQueryOptions } from './query-options'
import { QueryPlugin } from './query-plugin'
Expand Down Expand Up @@ -434,7 +434,7 @@ describe('useQuery', () => {
mountSimple({ key: ['todos'] }, { plugins: [pinia] })
await runTimers()

const cacheClient = useDataFetchingStore()
const cacheClient = useQueryCache()
expect(entryNodeSize(cacheClient.entryRegistry)).toBe(1)

mountSimple({ key: ['todos', 2] }, { plugins: [pinia] })
Expand All @@ -449,7 +449,7 @@ describe('useQuery', () => {
mountSimple({ key: ['todos', 2] }, { plugins: [pinia] })
await runTimers()

const cacheClient = useDataFetchingStore()
const cacheClient = useQueryCache()
expect(entryNodeSize(cacheClient.entryRegistry)).toBe(3)
})

Expand All @@ -469,7 +469,7 @@ describe('useQuery', () => {
)
await runTimers()

const cacheClient = useDataFetchingStore()
const cacheClient = useQueryCache()
expect(entryNodeSize(cacheClient.entryRegistry)).toBe(2)
})
})
Expand Down
4 changes: 2 additions & 2 deletions src/use-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
getCurrentInstance,
ComputedRef,
} from 'vue'
import { UseQueryStatus, useDataFetchingStore } from './data-fetching-store'
import { UseQueryStatus, useQueryCache } from './query-store'
import {
UseQueryOptions,
UseQueryOptionsWithDefaults,
Expand Down Expand Up @@ -66,7 +66,7 @@ export interface UseQueryReturn<TResult = unknown, TError = Error> {
export function useQuery<TResult, TError = Error>(
_options: UseQueryOptions<TResult>
): UseQueryReturn<TResult, TError> {
const store = useDataFetchingStore()
const store = useQueryCache()
const USE_QUERY_DEFAULTS = useQueryOptions()

const options = {
Expand Down

0 comments on commit b9ef0fb

Please sign in to comment.