Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove createStore option #5352

Merged
merged 2 commits into from
Apr 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions docs/react/guides/migrating-to-v5.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,16 +443,4 @@ Note that the infinite list must be bi-directional, which requires both `getNext

See the [Typescript Docs](../typescript#typing-query-options) for more details.

### CreateStore

We are now exposing a way to customize how queries are stored internally. Per default, a `Map` is used but, with the new `createStore` function, you can now use any data structure you want.

```ts
const queryClient = new QueryClient({
queryCache: new QueryCache({
createStore: () => new Map()
}),
})
```

[//]: # 'NewFeatures'
3 changes: 0 additions & 3 deletions docs/react/reference/QueryCache.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ Its available methods are:
- `onSettled?:` (data: unknown | undefined, error: unknown | null, query: Query) => void
- Optional
- This function will be called if some query is settled (either successful or errored).
- `createStore?: () => QueryStore`
- Optional
- This function will be called to create the store that will be used to store the queries. By default, a `Map` is used.

## Global callbacks

Expand Down
3 changes: 1 addition & 2 deletions packages/query-core/src/queryCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ interface QueryCacheConfig {
error: DefaultError | null,
query: Query<unknown, unknown, unknown>,
) => void
createStore?: () => QueryStore
}

interface NotifyEventQueryAdded extends NotifyEvent {
Expand Down Expand Up @@ -95,7 +94,7 @@ export class QueryCache extends Subscribable<QueryCacheListener> {

constructor(public config: QueryCacheConfig = {}) {
super()
this.#queries = config.createStore?.() ?? new Map<string, Query>()
this.#queries = new Map<string, Query>()
}

build<TQueryFnData, TError, TData, TQueryKey extends QueryKey>(
Expand Down
17 changes: 0 additions & 17 deletions packages/query-core/src/tests/queryCache.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,23 +329,6 @@ describe('queryCache', () => {
})
})

describe('QueryCacheConfig.createStore', () => {
test('should call createStore', async () => {
const createStore = vi.fn().mockImplementation(() => new Map())
new QueryCache({ createStore })
expect(createStore).toHaveBeenCalledWith()
})

test('should use created store', async () => {
const store = new Map()
const spy = vi.spyOn(store, 'get')

new QueryCache({ createStore: () => store }).get('key')

expect(spy).toHaveBeenCalledTimes(1)
})
})

describe('QueryCache.add', () => {
test('should not try to add a query already added to the cache', async () => {
const key = queryKey()
Expand Down