Skip to content
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 refactor to TypeScript (utils & kebabToCamelCase) #60149

Merged
merged 11 commits into from
Apr 10, 2024

Conversation

garridinsi
Copy link
Contributor

What?

Fixes #60147

Why?

To profit from the TypeScript features.

How?

Refactors the js files to ts and adds type annotation

Copy link

github-actions bot commented Mar 24, 2024

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: garridinsi <garridinsi@git.wordpress.org>
Co-authored-by: sirreal <jonsurrell@git.wordpress.org>
Co-authored-by: cbravobernal <cbravobernal@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @garridinsi! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Mar 24, 2024
@cbravobernal cbravobernal self-requested a review March 24, 2024 12:54
@cbravobernal cbravobernal added [Packages] Interactivity /packages/interactivity [Type] Code Quality Issues or PRs that relate to code quality labels Mar 24, 2024
Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvements adding missing types and JSDoc comments.

packages/interactivity/src/utils.ts Outdated Show resolved Hide resolved
replaceNode = [].concat( replaceNode );
const s = replaceNode[ replaceNode.length - 1 ].nextSibling;
function insert( c, r ) {
function insert( c: any, r: any ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional task: it would be helpful to unfold what c, r and s mean.

Copy link
Contributor

@cbravobernal cbravobernal Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I remember,

  • c is children.
  • r is root.
  • s is sibling.

cc @DAreRodz, correct me if I'm wrong.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_useEffect( () => {
let eff = null;
let isExecuting = false;

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One line comments can be shortened to:

// Notifies the callback function to execute after the next frame.

@gziolo gziolo requested a review from sirreal March 28, 2024 06:16
@gziolo
Copy link
Member

gziolo commented Mar 28, 2024

I see now that @c4rl0sbr4v0 has an alternative proposal open for adding TypeScript types to the same package but at a larger scale: #58718. So it wil require some coordination 😀

@garridinsi
Copy link
Contributor Author

garridinsi commented Mar 28, 2024

I see now that @c4rl0sbr4v0 has an alternative proposal open for adding TypeScript types to the same package but at a larger scale: #58718. So it wil require some coordination 😀

Hi! Yes! @c4rl0sbr4v0 made another PR but now is outdated as of some Interactivity API changes. This PR was made on WordCamp Torrelodones 2024 Contributor Day, and @c4rl0sbr4v0 is aware of this, as he was the Core table leader

@sirreal
Copy link
Member

sirreal commented Apr 2, 2024

Thanks for this work! I would like to review this but need a few days to get back to it. I see a few places we can improve and/or simplify things.

@garridinsi garridinsi requested a review from gziolo April 2, 2024 16:37
@garridinsi
Copy link
Contributor Author

Thanks @sirreal!

Sorry @gziolo for the Review request, was a miss click on my end

@cbravobernal
Copy link
Contributor

I see now that @c4rl0sbr4v0 has an alternative proposal open for adding TypeScript types to the same package but at a larger scale: #58718. So it wil require some coordination 😀

Don't worry, I can handle that coordination :-)

Copy link
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patience @garridinsi, I've left a number of suggestions and pushed a small change. I'm happy to push some of these myself or discuss further.

packages/interactivity/src/utils.ts Outdated Show resolved Hide resolved
packages/interactivity/src/utils.ts Outdated Show resolved Hide resolved
packages/interactivity/src/utils.ts Outdated Show resolved Hide resolved
packages/interactivity/src/utils.ts Outdated Show resolved Hide resolved
packages/interactivity/src/utils.ts Outdated Show resolved Hide resolved
packages/interactivity/src/types.ts Outdated Show resolved Hide resolved
packages/interactivity/src/utils.ts Outdated Show resolved Hide resolved
packages/interactivity/src/utils.ts Outdated Show resolved Hide resolved
packages/interactivity/src/utils/kebab-to-camelcase.ts Outdated Show resolved Hide resolved
packages/interactivity/src/utils.ts Outdated Show resolved Hide resolved
@cbravobernal cbravobernal force-pushed the feature/interactivity-api-to-ts branch from c0b25f0 to 5d556c7 Compare April 9, 2024 14:20
@cbravobernal
Copy link
Contributor

@sirreal I updated with all the changes you suggested. Feel free to check it again. Thanks!

Comment on lines 112 to 122
export function withScope<
Func extends ( ...args: any[] ) => Generator< any, any >,
>(
func: Func
): (
...args: Parameters< Func >
) => ReturnType< Func > extends Generator< any, infer Return >
? Promise< Return >
: never;
export function withScope< Func extends Function >( func: Func ): Func;
export function withScope( func ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to be a function so I could use function overloading for the typing here.

See types demo in practice

Copy link
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is ready, thanks folks!

@sirreal sirreal enabled auto-merge (squash) April 10, 2024 13:19
@sirreal sirreal merged commit 3b285be into WordPress:trunk Apr 10, 2024
64 checks passed
@github-actions github-actions bot added this to the Gutenberg 18.2 milestone Apr 10, 2024
@garridinsi garridinsi deleted the feature/interactivity-api-to-ts branch June 28, 2024 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Packages] Interactivity /packages/interactivity [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Interactivity API refactor to TypeScript (utils & kebabToCamelCase)
4 participants