-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Reorganize code to core + react
- Loading branch information
1 parent
bcecb54
commit 2de8528
Showing
33 changed files
with
311 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export { queryCache, queryCaches, makeQueryCache } from './queryCache' | ||
export { setFocusHandler } from './setFocusHandler' | ||
export { | ||
statusIdle, | ||
statusLoading, | ||
statusSuccess, | ||
statusError, | ||
stableStringify, | ||
setConsole, | ||
deepIncludes, | ||
} from './utils' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { setConsole, queryCache, queryCaches } from '../' | ||
import { deepEqual } from '../utils' | ||
|
||
describe('core/utils', () => { | ||
afterEach(() => { | ||
queryCaches.forEach(cache => cache.clear()) | ||
}) | ||
|
||
it('setConsole should override Console object', async () => { | ||
const mockConsole = { | ||
error: jest.fn(), | ||
} | ||
|
||
setConsole(mockConsole) | ||
|
||
await queryCache.prefetchQuery( | ||
'key', | ||
async () => { | ||
throw new Error('Test') | ||
}, | ||
{ | ||
retry: 0, | ||
} | ||
) | ||
|
||
expect(mockConsole.error).toHaveBeenCalled() | ||
|
||
setConsole(console) | ||
}) | ||
|
||
it('deepequal should return `false` for different dates', () => { | ||
const date1 = new Date(2020, 3, 1) | ||
const date2 = new Date(2020, 3, 2) | ||
|
||
expect(deepEqual(date1, date2)).toEqual(false) | ||
}) | ||
|
||
it('should return `true` for equal dates', () => { | ||
const date1 = new Date(2020, 3, 1) | ||
const date2 = new Date(2020, 3, 1) | ||
|
||
expect(deepEqual(date1, date2)).toEqual(true) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react' | ||
import { queryCache, makeQueryCache } from '../core' | ||
|
||
export const queryCacheContext = React.createContext(queryCache) | ||
|
||
export const queryCaches = [queryCache] | ||
|
||
export const useQueryCache = () => React.useContext(queryCacheContext) | ||
|
||
export function ReactQueryCacheProvider({ queryCache, children }) { | ||
const resolvedQueryCache = React.useMemo( | ||
() => queryCache || makeQueryCache(), | ||
[queryCache] | ||
) | ||
|
||
React.useEffect(() => { | ||
queryCaches.push(resolvedQueryCache) | ||
|
||
return () => { | ||
// remove the cache from the active list | ||
const i = queryCaches.indexOf(resolvedQueryCache) | ||
if (i > -1) { | ||
queryCaches.splice(i, 1) | ||
} | ||
// if the resolvedQueryCache was created by us, we need to tear it down | ||
if (queryCache == null) { | ||
resolvedQueryCache.clear() | ||
} | ||
} | ||
}, [resolvedQueryCache, queryCache]) | ||
|
||
return ( | ||
<queryCacheContext.Provider value={resolvedQueryCache}> | ||
{children} | ||
</queryCacheContext.Provider> | ||
) | ||
} |
Oops, something went wrong.