-
-
Notifications
You must be signed in to change notification settings - Fork 15.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
Remove node for tree-view example #1275
Conversation
renderChild(childId) { | ||
return ( | ||
<li key={childId}> | ||
<ConnectedNode id={childId} /> | ||
<ConnectedNode id={childId} handleRemoveChildClick={this.handleRemoveChildClick.bind(this, childId)} /> |
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.
Beside the uglyness I probably should have named this prop handleRemoveClick
.
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.
Binding is going to be expensive here because it's called a lot of times.
The child already knows its ID so there is no need to bind here—it can supply it as an argument by reading the props.
Neither are you, though. :-) The proper algorithm needs to create a list of the node to be removed and all of its descendants, and then remove all of those from the node array as well as remove the top node from its parent. |
#1275 is more like what I had in mind. Thanks! |
Argh, I meant to close #1274 :D |
Seems like you still need to slaughter all the grandkids. I don't see how you can do this in only the This is why we use data structure libraries. :-) |
I'll leave this to you to finish, no rush. |
39ffbb6
to
699a149
Compare
👍 I think it's going in the right direction. Might want to extract something like |
Sure thing, I just got home and was about to finish this 😄 And I did notice a semicolon slipped in, power of habit... not a big fan of semicolon-less myself yet. |
The |
@gaearon got time to take another look at this? |
@@ -40,6 +51,13 @@ class Node extends Component { | |||
<button onClick={this.handleIncrementClick}> | |||
+ | |||
</button> | |||
{' '} | |||
{parentId !== undefined ? |
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.
For the sake of consistency please use a typeof
check here instead.
Apart from a few bits this looks great to me. A nice extra would be to add some tests for the reducers and the helper functions but no pressures from you don't have time :-) |
Will do as soon as I find some time 😬 By the way is there a specific reason for using Also would you do something like |
We only use ES6 features in official examples. Array spread is ES6 but object spread is only a proposal now. |
As for |
Also not what I meant but you answered my question anyway :) |
@gaearon I added some basic tests for the root reducer. Those should also cover the reducer’s helper functions. I didn’t test edge or non happy flow cases, don’t know how far you want to go for examples. |
5a3e643
to
ffcd51d
Compare
This looks great! |
ffcd51d
to
e6cbc32
Compare
Thanks, also made the linter happy now :) |
Need anything else @gaearon? Maybe a |
Mind squashing into a single commit? |
e6cbc32
to
1b6488f
Compare
Done! |
A few things in master changed.
Thanks again! |
You’re killing me! 😧 Just kidding, will do tonight. |
Just did that myself (toned the color down instead of hover, works OK). |
I was honestly kidding but thanks man! |
No problem. I wanted to get it in ASAP before we blocked it with something else :-) |
Requested in #1269 for comparison against this alternative #1274 😄