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

[WIP] Separate unmount from destroy #603

Merged
merged 9 commits into from
Jun 1, 2017
Merged

[WIP] Separate unmount from destroy #603

merged 9 commits into from
Jun 1, 2017

Conversation

Rich-Harris
Copy link
Member

#592 revealed a slight flaw in how Svelte works — unmounting blocks (removing them from the DOM) and destroying them (removing event listeners etc) are coupled, when they actually serve separate purposes. In the case of #592, where a yield block exists inside an if block, we want to unmount the yield fragment when the if condition becomes falsy, not destroy it.

This PR separates the two things, so that blocks have unmount and destroy methods. fragment.destroy therefore no longer takes a detach argument that determines whether or not to unmount.

Generated code size has increased slightly as a result of this change, but as a follow-up we can determine during the preprocess step whether or not a given block needs a destroy method (i.e. does it contain event handlers, components etc, or does unmount take care of cleanup?) and omit it if possible, the same way we do with update methods.

@Rich-Harris
Copy link
Member Author

Should mention: this is most likely a breaking change in the edge case where your imported components were compiled with an old version of Svelte, a la #586.

#604 contains a proposal for handling this situation better at a more general level.

@Rich-Harris Rich-Harris merged commit c3fb711 into master Jun 1, 2017
@Rich-Harris Rich-Harris deleted the gh-592 branch June 1, 2017 02:44
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