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

chore(gatsby): Translate redux/nodes to TypeScript #21010

Merged
merged 15 commits into from
Mar 23, 2020
Merged

Conversation

blainekasten
Copy link
Contributor

@blainekasten blainekasten commented Jan 29, 2020

Description

This PR does a few things.

  1. Greatly expands the coverage of types for redux state
  2. Adds types to redux/nodes.ts
  3. Changes a function to return an array instead of modify an array argument (I'll add inline comments to show)
  4. Change some sort code to utilize a single common type. (I'll add inline comments to show)

@blainekasten blainekasten requested a review from a team as a code owner January 29, 2020 20:19
@blainekasten blainekasten changed the title [WIP] TS - Redux Nodes TS - Redux Nodes Jan 30, 2020

exports.addResolvedNodes = addResolvedNodes
return resolvedNodes
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function was changed to create an array and return it instead of modifying the argument array. Having an idempotent function feels better than having one with side effects. This function was only used in one place, and its usage was identical to this:

https://github.com/gatsbyjs/gatsby/pull/21010/files#diff-5d2176cb542d5c01d884139970be33fbR314

Copy link
Contributor

Choose a reason for hiding this comment

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

Need to check this. Could be faster, actually. Could also be slower. (Consider the case where each type has 100k nodes and they get merged. Before they were pushed onto the same node array, after they are pushed in their own array and later merged through a _.flatten() (which should really just be a .concat() imo)).

Copy link
Contributor

Choose a reason for hiding this comment

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

I checked this. It's slower, for sure, but in the case of the 150k ifsc benchmark it adds 5 to 10 seconds. I don't like slowing the build down for the user for the sake of something that only affects us at dev time, but I think the right choice is to do it anyways in this case ... :/

@pvdz pvdz changed the title TS - Redux Nodes typing(gatsby): TS - Redux Nodes Jan 31, 2020
Copy link
Contributor

@pvdz pvdz left a comment

Choose a reason for hiding this comment

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

(I don't know if typing() is a proper lerna thing. Probably just chore(), but we should look into that)

(To the point of Greatly expands the coverage of types for redux state; I think it would be good if we had a coverage report included in PRs.)

This touches perf sensitive stuff and we need to benchmark it first. Numbers will lead the way.

packages/gatsby/src/redux/nodes.ts Show resolved Hide resolved
packages/gatsby/src/redux/nodes.ts Outdated Show resolved Hide resolved
packages/gatsby/src/redux/nodes.ts Outdated Show resolved Hide resolved

exports.addResolvedNodes = addResolvedNodes
return resolvedNodes
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to check this. Could be faster, actually. Could also be slower. (Consider the case where each type has 100k nodes and they get merged. Before they were pushed onto the same node array, after they are pushed in their own array and later merged through a _.flatten() (which should really just be a .concat() imo)).

packages/gatsby/src/redux/nodes.ts Outdated Show resolved Hide resolved
packages/gatsby/src/redux/nodes.ts Outdated Show resolved Hide resolved
packages/gatsby/src/redux/nodes.ts Outdated Show resolved Hide resolved
packages/gatsby/src/redux/run-sift.js Show resolved Hide resolved
Copy link
Contributor

@pvdz pvdz left a comment

Choose a reason for hiding this comment

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

Did a fairly thorough review. It looks good! I do have a few questions.

.eslintrc.js Show resolved Hide resolved
},
})
for (const node of nodes.values()) {
const resolved = await resolver(node)
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it possible that the first returned promise is actually this one? So the return value wouldn't be undefined, but whatever resolved is.

I'm a little surprised TS is accepting that. Maybe because Resolver is typed as any.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you have any idea what it should be typed as? I don't yet know what this resolver really is.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, not when I was reviewing it. So if TS is fine with it, I guess let's just keep it like this and revisit that later.

packages/gatsby/src/redux/nodes.ts Outdated Show resolved Hide resolved
packages/gatsby/src/redux/nodes.ts Show resolved Hide resolved
packages/gatsby/src/redux/types.ts Outdated Show resolved Hide resolved
packages/gatsby/src/redux/types.ts Outdated Show resolved Hide resolved
packages/gatsby/src/redux/actions/internal.ts Outdated Show resolved Hide resolved
@blainekasten blainekasten changed the title typing(gatsby): TS - Redux Nodes chore(gatsby): Translate redux/nodes to TypeScript Mar 13, 2020
@blainekasten blainekasten requested a review from pvdz March 13, 2020 19:49
pvdz
pvdz previously approved these changes Mar 13, 2020
Copy link
Contributor

@pvdz pvdz left a comment

Choose a reason for hiding this comment

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

Let's do this! 💃

@blainekasten blainekasten added the bot: merge on green Gatsbot will merge these PRs automatically when all tests passes label Mar 14, 2020
@blainekasten blainekasten requested a review from pvdz March 23, 2020 16:03
@gatsbybot gatsbybot merged commit ccf3ec2 into master Mar 23, 2020
@delete-merged-branch delete-merged-branch bot deleted the ts/redux-nodes branch March 23, 2020 16:23
@pvdz
Copy link
Contributor

pvdz commented Mar 24, 2020

Published in [email protected] (just in case we need to bisect it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: merge on green Gatsbot will merge these PRs automatically when all tests passes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants