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

Optimized stringMap calculation #1211

Merged
merged 3 commits into from
Jan 7, 2019

Conversation

MxFr
Copy link

@MxFr MxFr commented Dec 20, 2018

This is the optimization I spoke of in a recent issue (#1207).
Instead of iterating (including formatting, cleaning et.) the data twice and extracing a different property each time, the data is iterated once and both properties are extracted.

To achive this I had to adapt reduceChildren to allow different kinds of reduce functions instead of accumulating every result in an array, otherwise I would have ended up with an array of objects containing the x and y properties, which would have required another iteration for unwrapping.


const initialMemo = { x: [], y: [] };
const combine = (memo, datum) => ({
x: datum.x ? memo.x.concat(datum.x) : memo.x,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these should be datum.x !== undefined ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Though maybe this is unnecessary since the case where these would be empty strings is a bit contrived.

Copy link
Author

Choose a reason for hiding this comment

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

!== undefined is better, I'll change that.

@boygirl
Copy link
Contributor

boygirl commented Dec 21, 2018

sorry about the timing. We just added prettier. Would you mind rebasing:

> git rebase master -p -x ours
> yarn nps format

@boygirl
Copy link
Contributor

boygirl commented Jan 2, 2019

Happy New Year! These changes are desirable. Do you have a moment to rebase?

@MxFr MxFr force-pushed the optimize-stringMap-calculation branch from 88bc033 to 5258110 Compare January 7, 2019 07:42
@MxFr
Copy link
Author

MxFr commented Jan 7, 2019

Sorry for being so unresponsive, but I was on a vacation over chrismas. The rebase to prettier is now done.

@boygirl
Copy link
Contributor

boygirl commented Jan 7, 2019

🎉 Thanks!

@boygirl boygirl merged commit 214f72d into FormidableLabs:master Jan 7, 2019
@MxFr MxFr deleted the optimize-stringMap-calculation branch January 8, 2019 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants