-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Field API: simplify normalization #73546
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
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
fd9364a to
47f458c
Compare
| * @return A field type definition. | ||
| */ | ||
| export default function getNormalizeFieldFunction< Item >( | ||
| function getDefaultProperties< Item >( |
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 don't understand what this function is about?
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 guess your question is why not to inline this within normalizeFields, right?
I thought it'd be best that it stays as a separate function because this acts like the public registry we don't have. So when we have the registry, it'd be a simple call switch.
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, I'm actually not sure what this function is about. Is it some kind of getFieldTypeByName or something? If that's the case, I kind of expected this to loop through the fields and compare "id" or something. The if/else or switch feels a bit weird.
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.
This function just loads the defaults defined by each type in the corresponding file. I guess getFieldTypeByName could work as a name as well.
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.
Should it be something like
[ string, number ... ].find( fieldType => fieldType.type === type )
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.
That's neat, I pushed it at eeb173c
youknowriad
left a comment
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 find this a lot clearer. Thanks for the follow-up
eeb173c to
d472229
Compare
| | 'over'; | ||
|
|
||
| export type FieldType = | ||
| export type FieldTypeName = |
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.
@youknowriad I lost the comment attached to the commit, so continuing here: perhaps FieldTypeName is a good fit for this one.
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.
Works for me, although "string" would have worked for me assuming we'll allow registration at some point.
Follow-up to #73387
Related #73548
What?
After #73387 each field type provided a normalize function that effectively acted as a factory for the given field type. This changes it back to return an object with the default properties.
Why?
See feedback #73387
Testing Instructions
Smoke test DataViews storybook and the Site Editor (Pages, Templates, Patterns screens).