Thunberg087 / vue-fragment

a very candide fragment component for Vue.js
http://jsfiddle.net/cdkn5wL3/
670 stars 51 forks source link

What is the function of the parent.removeChild method? #23

Closed GreenMashimaro closed 5 years ago

GreenMashimaro commented 5 years ago

https://github.com/y-nk/vue-fragment/blob/ad86ea2fa3aadd8fa980f2d7f240c8214f8b32bd/src/component.js#L69

Hello, excuse me, what is the function of this parent.removeChild method? When I debugged the code, I found that this method was not used.

If there is no method in use, I recommend deleting it and keeping the code clean.

y-nk commented 5 years ago

In case of unmounting the fragment, Vue will try to unmount the fragment root node. In that case, instead of removing the root node, we remove all the fragment's children, and then turn this method back to normal.

This behavior is enforced by the if statement in L70, and you can see that in any other case than removing the fragment itself, the parent.removeChild behaves as the original behavior.

https://github.com/y-nk/vue-fragment/blob/ad86ea2fa3aadd8fa980f2d7f240c8214f8b32bd/src/component.js#L70-L83

GreenMashimaro commented 5 years ago

Thank you very much for your reply. I see. I haven't considered it comprehensively enough. If necessary, consider adding a short comment description to this code for other developers to understand.