-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(oneFetchye): Introduce new imperative api
deprecate makeOneServerFetchye
- Loading branch information
1 parent
7f768d2
commit f6ec47e
Showing
4 changed files
with
89 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import oneFetchye from '../src/oneFetchye'; | ||
|
||
const mockOneCacheSymbol = Symbol('oneCache'); | ||
jest.mock('../src/OneCache', () => jest.fn(() => mockOneCacheSymbol)); | ||
jest.mock('fetchye', () => ({ | ||
makeServerFetchye: jest.fn((...makeFetchyeArgs) => jest.fn((...fetcheArgs) => Promise.resolve( | ||
{ makeFetchyeArgs, fetcheArgs } | ||
))), | ||
})); | ||
describe('oneFetchye', () => { | ||
it('should return a one-app-thunk that calls fetchye', async () => { | ||
expect.assertions(1); | ||
const fetchyeParams = [Symbol('fetchyeArgs 1'), Symbol('fetchyeArgs 2')]; | ||
const fetchyeThunk = oneFetchye(...fetchyeParams); | ||
const thunkParams = [Symbol('dispatch'), Symbol('getState'), Symbol('fetchClient')]; | ||
const response = await fetchyeThunk( | ||
thunkParams[0], thunkParams[1], { fetchClient: thunkParams[2] } | ||
); | ||
expect(response).toStrictEqual({ | ||
fetcheArgs: fetchyeParams, | ||
makeFetchyeArgs: [ | ||
{ | ||
cache: mockOneCacheSymbol, | ||
fetchClient: thunkParams[2], | ||
store: { | ||
dispatch: thunkParams[0], | ||
getState: thunkParams[1], | ||
}, | ||
}, | ||
], | ||
}); | ||
}); | ||
}); |
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,13 @@ | ||
import { makeServerFetchye } from 'fetchye'; | ||
import OneCache from './OneCache'; | ||
|
||
const oneFetchye = (...fetchyeArgs) => async (dispatch, getState, { fetchClient }) => { | ||
const fetchye = makeServerFetchye({ | ||
store: { getState, dispatch }, | ||
fetchClient, | ||
cache: OneCache(), | ||
}); | ||
return fetchye(...fetchyeArgs); | ||
}; | ||
|
||
export default oneFetchye; |