-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
[RFR] Use data provider without saga #3468
Conversation
@@ -4,6 +4,7 @@ import { act, cleanup } from 'react-testing-library'; | |||
|
|||
import EditController from './EditController'; | |||
import renderWithRedux from '../util/renderWithRedux'; | |||
import { DataProviderContext } from '../dataProvider'; |
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.
Not used ?
const useDataProvider = (): DataProviderHookFunction => { | ||
const dispatch = useDispatch() as Dispatch; | ||
const dataProvider = useContext(DataProviderContext) || defaultDataProvider; | ||
const isOptimistic = useSelector( |
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.
I'm not sure we need this reducer to handle optimistic detection. Can't w achieve the same with metas on the action ?
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.
No, because the use case is the following:
- user clicks on Delete post
- the
useDataProvider
hook optimistically deletes the record from the store and redirects to the post list - the list calls the dataProvider for the list of posts on mount
- While waiting for the result, the list shows the posts from the sorte, where the deleted post has been removed
- As the deletion wasn't performed on the server yet, the server returns results including the deleted record
- The list shows the deleted post again
To avoid that, the 'optimistic mode' blocks queries while an optimistic update is pending, so 3 and 5 never happen.
fetch
directory inra-core
todataProvider
<DataProviderContext>
and use it in<AdminCore>
fetch
andundo
sagas logic insideuseDataProvider
useDataProvider
by no longer including thefetch
metaEventEmitter
Overall this is completely transparent unless you're using a custom app. The benefit is that the
useDataProvider
code is much easier to follow, with less layers to look at. Also, mergingfetch
andundo
really makes sense as the Undo feature can only undo a fetch action.The cons are the use of the EventEmitter, which I preferred over a temporary redux state, and the removal of the possibility to hack the react-admin
dataProvider
logic by replacing thefetch
saga.From that point on, technically we could remove the
fetch
andauth
sagas, as well as thecrudXXX
action creators. However, we keep them for backward compatibility's sake.