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

Object3D: Add removeAll(). #20478

Merged
merged 1 commit into from
Oct 8, 2020
Merged

Object3D: Add removeAll(). #20478

merged 1 commit into from
Oct 8, 2020

Conversation

Mugen87
Copy link
Collaborator

@Mugen87 Mugen87 commented Oct 8, 2020

Related issues:

Fixed #20414.

Description

I like removeAll() more than the clear() since the relation to remove() is more obvious. Or in other words, it should be easier for user to figure out what removeAll() does if they are familiar with the semantics of remove().

@mrdoob
Copy link
Owner

mrdoob commented Oct 8, 2020

I find clear() prettier, but now that they have added replaceAll() to Javascript... on top of what you said, following the pattern feels right.

@mrdoob mrdoob added this to the r122 milestone Oct 8, 2020
@mrdoob mrdoob merged commit 68976a1 into mrdoob:dev Oct 8, 2020
@mrdoob
Copy link
Owner

mrdoob commented Oct 8, 2020

Thanks!

@@ -314,6 +314,11 @@ <h3>[method:this remove]( [param:Object3D object], ... )</h3>
Removes *object* as child of this object. An arbitrary number of objects may be removed.
</p>

<h3>[method:this removeAll]()</h3>
<p>
Removes all child objects.
Copy link
Collaborator

Choose a reason for hiding this comment

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

removeAll(). Remove all what?

Does it remove the object? The object's children? The children of the children?

And how are they disposed?

This perhaps should be an app-level method, not a library method.

Copy link
Owner

@mrdoob mrdoob Oct 8, 2020

Choose a reason for hiding this comment

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

Removes all children, but doesn't traverse the hierarchy.
I've found myself needing this pretty often, but yes... the dispose situation can be confusing...

Copy link
Collaborator

Choose a reason for hiding this comment

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

I do not think it belongs in the library. The proper implementation is app-specific.

But at a minimum, I think the name should be changed to something else.

Copy link
Collaborator Author

@Mugen87 Mugen87 Oct 9, 2020

Choose a reason for hiding this comment

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

Then we should probably change remove() to removeChild(), too. Or event to removeChildButNotChildrenOfChild()...

TBH, I think the name (and the method itself) is totally fine. Improving the documentation to provide more clarity is of course always a good idea.

Copy link
Owner

Choose a reason for hiding this comment

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

But at a minimum, I think the name should be changed to something else.

Neither Mugen87 nor I are native english speakers. Any help with naming is always welcome 🙏

Copy link
Owner

Choose a reason for hiding this comment

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

I'm going to go with .clear() which is what I used in ui.js.

Copy link
Owner

Choose a reason for hiding this comment

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

Copy link
Owner

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

@Mugen87 Mugen87 Oct 14, 2020

Choose a reason for hiding this comment

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

This also breaks the TS build:

src/cameras/CubeCamera.d.ts(16,2): error TS2416: Property 'clear' in type 'CubeCamera' is not assignable to the same property in base type 'Object3D'.

Copy link
Owner

Choose a reason for hiding this comment

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

Yep, I'll think about this.

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.

Object3D: Add removeAll or clear.
3 participants