-
-
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
[WIP] add useOptimisticQuery hook #3248
Conversation
That hook fetches the data provider and returns the data from the a=cache as soon as it finds it.
): CrudGetOneAction => ({ | ||
type: CRUD_GET_ONE, | ||
payload: { id }, | ||
meta: { | ||
resource, | ||
fetch: GET_ONE, | ||
basePath, |
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.
decoupling side effects, refs #2952
const { data: record, loading } = useGetOne( | ||
resource, | ||
id, | ||
{ |
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.
now it's the controller who decides the side effects, not the action creator
* @returns {GetOneResponse} An object with the shape { data, error, loading, loaded } | ||
*/ | ||
const useOptimisticQuery = ( | ||
action: FetchAction, |
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 so sure about the signature of this one. Should it accept:
- an action returned by an action creator, as I did here, or
- a quadruplet
{ type, resource, payload, meta }
, like theuseQuery
action
In the latter case, we don't need the crud action creators anymore.
After a good night's sleep, and the discernment of a week day, I think this experimentation is useful but does not show the best solution.
useQuery(query, options);
//example
const useGetOne = (resource, id, sideEffects) => useQuery(
{ type: GET_ONE, resource: 'posts', payload: ' { id: 123 } },
{ action: CRUD_GET_ONE, selector: state => state.admin.resources[resource].data[id], meta: sideEffects } It's not completely similar to the So I'm going to close this PR and start working on a better implementation. (note for self: do not work on weekends) |
Allows to group two pieces of controller logic:
I also introduced a new reducer to store the loading state of every request, which allows to pass that information to the view.
I updated the Edit and Show controllers to use that new hook. The
isLoading
prop is now relative to the main query (not the global loading state).