-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
split up middleware, add OptionalPromise, add cache entry lifecycle #1034
Merged
phryneas
merged 21 commits into
reduxjs:feature/v1.6-integration
from
phryneas:feature/lifecycles
May 13, 2021
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
6ae000c
split up middleware into multiple files
d3e3f23
add cache lifecycle
4e062a8
add `onQuery` lifecycle
phryneas 6fe71be
Merge branch 'feature/v1.6-integration' into feature/lifecycles
phryneas a98bdec
Merge remote-tracking branch 'origin/feature/v1.6-integration' into f…
phryneas ee1cc38
tweaks, tests
phryneas 925c455
describe scenarios for testing cacheLifecycle
phryneas 0e9571e
basic lifecycle tests
phryneas c2f894e
add `getCacheEntry`, add more tests
phryneas 568d520
small guard, fix tests
phryneas d9d7bd4
deprecation of old lifecycle with "best effort" fallback
phryneas e2e1fbc
move lifecycle callbacks type definitions into their respective middl…
phryneas 89b5813
force loading of references?
phryneas 40b47a8
`updateCacheEntry`, `.undo`
phryneas 35c658c
fix weird type inference test error?
phryneas 0624edd
fix duplicate running lifecycles
phryneas 8a52b34
mutation tests, mutation unsubscribe fix, mutation selector fix
phryneas 9755534
fix queryLifecycle mutation `getCacheEntry`, more tests
phryneas cc22a09
move promises into api object
phryneas 1f0b4e9
docs updates
phryneas 2b7c65b
Merge remote-tracking branch 'origin/feature/v1.6-integration' into f…
phryneas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -277,6 +277,26 @@ export function buildCreateApi<Modules extends [Module<any>, ...Module<any>[]]>( | |
} | ||
x.providesTags ??= x.provides | ||
} | ||
if (x.onStart || x.onSuccess || x.onError) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, glad u added a message here! |
||
if ( | ||
typeof process !== 'undefined' && | ||
process.env.NODE_ENV === 'development' | ||
) { | ||
console.warn( | ||
'`onStart`, `onSuccess` and `onError` have been replaced by `onQuery`, please change your code accordingly' | ||
) | ||
} | ||
x.onQuery ??= async (arg, api, { resultPromise }) => { | ||
const queryApi = { ...api, context: {} } | ||
x.onStart?.(arg, queryApi) | ||
try { | ||
const result = await resultPromise | ||
x.onSuccess?.(arg, queryApi, result, undefined) | ||
} catch (error) { | ||
x.onError?.(arg, queryApi, error, undefined) | ||
} | ||
} | ||
} | ||
return { ...x, type: DefinitionType.query } as any | ||
}, | ||
mutation: (x) => { | ||
|
@@ -292,6 +312,26 @@ export function buildCreateApi<Modules extends [Module<any>, ...Module<any>[]]>( | |
} | ||
x.invalidatesTags ??= x.invalidates | ||
} | ||
if (x.onStart || x.onSuccess || x.onError) { | ||
if ( | ||
typeof process !== 'undefined' && | ||
process.env.NODE_ENV === 'development' | ||
) { | ||
console.warn( | ||
'`onStart`, `onSuccess` and `onError` have been replaced by `onQuery`, please change your code accordingly' | ||
) | ||
} | ||
x.onQuery ??= async (arg, api, { resultPromise }) => { | ||
const queryApi = { ...api, context: {} } | ||
x.onStart?.(arg, queryApi) | ||
try { | ||
const result = await resultPromise | ||
x.onSuccess?.(arg, queryApi, result, undefined) | ||
} catch (error) { | ||
x.onError?.(arg, queryApi, error, undefined) | ||
} | ||
} | ||
} | ||
return { ...x, type: DefinitionType.mutation } as any | ||
}, | ||
}) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤣
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Genius, isn't it? :D
I was like "the old API had it, so we mayybe need it here too?" and then "how on earth do I get that?". Yup.