[WIP] Separate unmount from destroy #603
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#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 anif
block, we want to unmount the yield fragment when theif
condition becomes falsy, not destroy it.This PR separates the two things, so that blocks have
unmount
anddestroy
methods.fragment.destroy
therefore no longer takes adetach
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 doesunmount
take care of cleanup?) and omit it if possible, the same way we do withupdate
methods.