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

Fix region clean up, when view destroy #3262

Closed
wants to merge 1 commit into from

Conversation

ftdebugger
Copy link
Contributor

Region with "replaceElement" setting don't restore region element, when view was destroyed by self. Because view element remove from DOM before destroy event fired. Listen before:destroy fix this problem.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 1dd5754 on ftdebugger:next into b5e1066 on marionettejs:next.

@@ -72,6 +72,10 @@ const Region = MarionetteObject.extend({

this._attachView(view, options);

if (this._isReplaced) {
view.on('before:destroy', this._empty, this);
Copy link
Member

@rafde rafde Nov 17, 2016

Choose a reason for hiding this comment

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

describe('and restore, when view was self destroyed', function() {
beforeEach(function() {
this.view.trigger('before:destroy', this.view);
this.view._removeElement();
Copy link
Member

Choose a reason for hiding this comment

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

I think this.view.destroy(); should do the event emitting instead in order to match a real scenario.

@paulfalgout
Copy link
Member

paulfalgout commented Nov 17, 2016

👏 Good find.

@rafde I don't think before:destroy will work everywhere because empty checks if a view is destroyed.

However I think the easiest cheapest solution to this is to add view.on('before:destroy', this._restoreEl, this); to _replaceEl

https://jsfiddle.net/bbapmrsw/1/

I don't think clean up of this event will be necessary either as the events will be cleaned up. _restoreEl will be called twice, but will bail the second time at the isReplaced check.

@paulfalgout paulfalgout added this to the v3.2 milestone Nov 18, 2016
@paulfalgout
Copy link
Member

@ftdebugger any interest on revising this a bit?

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