-
Notifications
You must be signed in to change notification settings - Fork 4.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
Refactor deleteEntityRecord to use thunks instead of generators #34386
Conversation
Size Change: -1 B (0%) Total Size: 1.04 MB
ℹ️ View Unchanged
|
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.
Code LGTM and looks like we have an E2E test that ought to cover this.
it( 'Allows widget deletion to be undone', async () => { |
{ __unstableFetch = null } = {} | ||
) { | ||
const entities = yield getKindEntities( kind ); | ||
{ __unstableFetch = triggerFetch } = {} |
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.
Just a note so that we don't forget.
Right now __unstableFetch
is so named because it's a "private" argument used only by the batch action. It would be nicer, I think, to remove the argument in favour of currying deleteEntityRecord
, saveEntityRecord
, etc. and only exporting a partial application.
We can't easily do this until everything uses thunks.
const createDeleteEntityRecordAction = ( fetch ) => ( kind, name, recordId, query ) => {
...
};
export const deleteEntityRecord = createDeleteEntityRecordAction( triggerFetch );
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 really like that idea, it has some real Haskell vibes to it! :-)
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 paid $20k for a computer science degree and now I know how to use words like "currying" in a sentence.
|
||
yield removeItems( kind, name, recordId, true ); | ||
await dispatch( removeItems( kind, name, recordId, true ) ); |
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.
Sync action that removes items from the in-memory cache in the store.
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 am still not on board with removing await
when we dispatch a function call because it assumes we know the implementation details of that function. I think we're pretty close to having all the actions refactored though so maybe that would be enough to start the larger discussion? I have the resolvers in mind too, but maybe they're not a blocker for that.
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.
it assumes we know the implementation details of that function.
We only need to know the type of what the removeItems
function returns. If that's a function (thunk) that returns a promise, we might want to await it. We already know what the parameters of removeItems
are, and it's not an implementation details either.
a6cba1f
to
7670420
Compare
Builds on top of the thunks support added in #27276 and refactors just the parts of core-data required to make the
deleteEntityRecord
work (see #28389 from @jsnajdr).Test plan: