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

Remove node for tree-view example #1275

Merged
merged 1 commit into from
Feb 2, 2016
Merged

Conversation

CrocoDillon
Copy link
Contributor

Requested in #1269 for comparison against this alternative #1274 😄

renderChild(childId) {
return (
<li key={childId}>
<ConnectedNode id={childId} />
<ConnectedNode id={childId} handleRemoveChildClick={this.handleRemoveChildClick.bind(this, childId)} />
Copy link
Contributor Author

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.

Copy link
Contributor

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.

@erikras
Copy link
Contributor

erikras commented Jan 25, 2016

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.

@gaearon
Copy link
Contributor

gaearon commented Jan 25, 2016

#1275 is more like what I had in mind. Thanks!

@gaearon gaearon closed this Jan 25, 2016
@gaearon gaearon reopened this Jan 25, 2016
@gaearon
Copy link
Contributor

gaearon commented Jan 25, 2016

Argh, I meant to close #1274 :D

@CrocoDillon
Copy link
Contributor Author

@erikras yeah I just uploaded what I have so far to compare to yours :D

@gaearon I won't have time to finish this today, feel free to go with Erik's PR instead if you both can't wait!

@erikras
Copy link
Contributor

erikras commented Jan 25, 2016

Seems like you still need to slaughter all the grandkids. I don't see how you can do this in only the node() reducer. Just snipping the branch isn't good enough; you have to iterate though all the descendants and remove them as well.

This is why we use data structure libraries. :-)

@gaearon
Copy link
Contributor

gaearon commented Jan 25, 2016

I'll leave this to you to finish, no rush.

@gaearon
Copy link
Contributor

gaearon commented Jan 26, 2016

👍 I think it's going in the right direction. Might want to extract something like getAllDescendantIds(state, nodeId) and deleteMany(state, ids) when you implement recursive removal.

@CrocoDillon
Copy link
Contributor Author

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.

@CrocoDillon
Copy link
Contributor Author

The getAllDescendantIds function could probably be optimized since it’s creating a new array for every childId. But either way is this a little bit like what you had in mind?

@CrocoDillon
Copy link
Contributor Author

@gaearon got time to take another look at this?

@@ -40,6 +51,13 @@ class Node extends Component {
<button onClick={this.handleIncrementClick}>
+
</button>
{' '}
{parentId !== undefined ?
Copy link
Contributor

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.

@gaearon
Copy link
Contributor

gaearon commented Jan 27, 2016

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 :-)

@CrocoDillon
Copy link
Contributor Author

Will do as soon as I find some time 😬

By the way is there a specific reason for using Object.assign instead of spread?

Also would you do something like const node = combineReducers({ id, counter, childIds }) or keep it simple and extract only a childIds reducer?

@gaearon
Copy link
Contributor

gaearon commented Jan 28, 2016

By the way is there a specific reason for using Object.assign instead of spread?

We only use ES6 features in official examples. Array spread is ES6 but object spread is only a proposal now.

@gaearon
Copy link
Contributor

gaearon commented Jan 28, 2016

As for childIds I didn't mean it to be top-level reducer. I meant to extract a function from node that operates just on that field. Reducer composition. This reducer wouldn't be used anywhere else.

@CrocoDillon
Copy link
Contributor Author

This reducer wouldn't be used anywhere else.

Also not what I meant but you answered my question anyway :)

@CrocoDillon
Copy link
Contributor Author

@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.

@gaearon
Copy link
Contributor

gaearon commented Jan 30, 2016

This looks great!

@CrocoDillon
Copy link
Contributor Author

Thanks, also made the linter happy now :)

@CrocoDillon
Copy link
Contributor Author

Need anything else @gaearon? Maybe a DECREMEMT action while at it? ;)

@gaearon
Copy link
Contributor

gaearon commented Feb 1, 2016

Mind squashing into a single commit?

@CrocoDillon
Copy link
Contributor Author

Done!

@gaearon
Copy link
Contributor

gaearon commented Feb 2, 2016

A few things in master changed.
Please would you:

  1. Rebase on master
  2. Add babel-register as dep and use it instead of babel/register
  3. Use crossenv when specifying NODE_ENV
  4. Tweak Delete to only be visible when Node is hovered? Otherwise there's too much noise.
  5. Squash

Thanks again!

@CrocoDillon
Copy link
Contributor Author

You’re killing me! 😧

Just kidding, will do tonight.

@gaearon gaearon merged commit 1b6488f into reduxjs:master Feb 2, 2016
@gaearon
Copy link
Contributor

gaearon commented Feb 2, 2016

Just did that myself (toned the color down instead of hover, works OK).

@CrocoDillon
Copy link
Contributor Author

I was honestly kidding but thanks man! :shipit:

@gaearon
Copy link
Contributor

gaearon commented Feb 2, 2016

No problem. I wanted to get it in ASAP before we blocked it with something else :-)
Thank you for your contribution!

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.

3 participants