-
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
Interactivity API: Added comments for directive parsing #61456
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. |
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.
Hi there!
I was thinking about doing a refactor (setting the variables names with what they should be, instead of 'prefix' or 'suffix' rather than adding code comments 😅
Thanks for contributing on this issue!
@cbravobernal I've made the changes you suggested! Now, instead of using 'prefix' and 'suffix', I've renamed the variables more clearly. Thanks! |
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 leaving this on Request changes
to wait for #61409 to be merged and also to get some more feedback about the naming of those vars.
packages/interactivity/src/vdom.ts
Outdated
const directiveMatch = directiveParser.exec( name ); | ||
// The reducer function accumulates the __directives object. | ||
( obj, [ directiveName, namespace, inputValue ] ) => { | ||
// Check if the directive name matches the expected format. |
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.
// Check if the directive name matches the expected format. |
Same here.
packages/interactivity/src/vdom.ts
Outdated
props.__directives = directives.reduce( | ||
( obj, [ name, ns, value ] ) => { | ||
const directiveMatch = directiveParser.exec( name ); | ||
// The reducer function accumulates the __directives object. |
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.
// The reducer function accumulates the __directives object. |
Same here.
packages/interactivity/src/vdom.ts
Outdated
@@ -127,18 +131,22 @@ export function toVdom( root ) { | |||
SCRIPT_DEBUG === true | |||
) { | |||
// eslint-disable-next-line no-console | |||
console.warn( `Invalid directive: ${ name }.` ); | |||
console.warn( |
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.
Let's wait for #61409 to be merged and update with its function.
packages/interactivity/src/vdom.ts
Outdated
const directiveType = directiveMatch[ 1 ] || ''; | ||
const directiveInput = directiveMatch[ 2 ] || 'default'; | ||
|
||
// Creating or updating the array for the specific directive type in the directives object. |
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.
// Creating or updating the array for the specific directive type in the directives object. |
Same here
packages/interactivity/src/vdom.ts
Outdated
namespace: ns ?? currentNamespace(), | ||
value, | ||
suffix, | ||
// Splitting the directive name into directive type and input. |
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.
// Splitting the directive name into directive type and input. |
Same here
packages/interactivity/src/vdom.ts
Outdated
value, | ||
suffix, | ||
// Splitting the directive name into directive type and input. | ||
const directiveType = directiveMatch[ 1 ] || ''; |
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.
const directiveType = directiveMatch[ 1 ] || ''; | |
const directive = directiveMatch[ 1 ] || ''; |
I think directive is a better name.
packages/interactivity/src/vdom.ts
Outdated
suffix, | ||
// Splitting the directive name into directive type and input. | ||
const directiveType = directiveMatch[ 1 ] || ''; | ||
const directiveInput = directiveMatch[ 2 ] || 'default'; |
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.
Could be "event" or "directiveEvent" a better name for this?
Not sure, cause they are events in data-wp-on-document
or data-wp-on-window
or data-wp-on
. But can also be styles or classes in data-wp-class--
or data-wp--style
. Even attributes for data-wp-bind
What do you think about it? Let's ping some folks with experience developing with the Interactivity API to get some feedback.
Ping: @ryanwelcher , @luisherranz , @DAreRodz or @sethrubenstein
Hi @cbravobernal I have made changes as per your suggestion. Now waiting for replies from other folks. |
Sorry @amitraj2203 but we are not going to merge this PR. The prefix word is being used through all the Interactivity codebase, and is a bigger refactor than expected. |
What?
Fixes: #61455
Why?
It adds comments for directive parsing
How?
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast