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

Don't detach pre-existing HTML when view's el is already in the region #3260

Merged

Conversation

paulfalgout
Copy link
Member

Resolves #3227

This PR also moves some of Region.show into a _setupChildView function which mirrors what is happening in a CollectionView currently and helps reduce the length of the show function which grew to handle the should empty check. Additionally moved the currentView = view to show to make the attach functions between CollectionView and Region more similar.

In the specs, there was a failing test regarding “when setting the "replaceElement" class option”. I believe this test was failing because it was reusing this.view which wasn’t cleaned up in a prior test. So effectively this.view was currently already shown in another region. I switched this to this.view1 which is instantiated as part of this describe block (or closer at least) and should be better for these tests.

Resolves marionettejs#3227

This PR also moves some of `Region.show` into a `_setupChildView` function which mirrors what is happening in a CollectionView currently and helps reduce the length of the `show` function which grew to handle the should empty check.

In the specs, there was a failing test regarding “when setting the "replaceElement" class option”.  I believe this test was failing because it was reusing `this.view` which wasn’t cleaned up in a prior test.  So effectively `this.view` was currently already shown in another region.  I switched this to `this.view1` which is instantiated as part of this `describe` block (or closer at least) and should be better for these tests.
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 0f01915 on paulfalgout:bugfix/avoid-preexisting-detach into b5e1066 on marionettejs:next.

@paulfalgout paulfalgout added this to the v3.2 milestone Dec 16, 2016
// has been destroyed we can not reuse it.
view.on('destroy', this._empty, this);
// Assume an attached view is already in the region for pre-existing DOM
if (!view._isAttached) {
Copy link
Member

Choose a reason for hiding this comment

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

Should we document this assumption?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think pre-existing DOM stuff needs its own documentation: #3128 (comment) and this is only a small portion of what isn't fully documented.

@scott-w scott-w merged commit 5c93797 into marionettejs:next Dec 23, 2016
@paulfalgout paulfalgout mentioned this pull request Jan 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants