3gwebtrain
3gwebtrain

Reputation: 15303

Marionette `close()` or `empty()`

In my app I am adding views to content region and header,footer. before I add a view, I am trying to find if there is a controller exist. if so i am trying to close those regions before I add another like this:

if(socialApp.Controller) {
 socialApp.Controller.layout.header.close();
 socialApp.Controller.layout.content.close();
 socialApp.Controller.layout.footer.close();
}

But I am getting error.

Instead of close i used the empty() method is works fine.

if(socialApp.Controller) {
     socialApp.Controller.layout.header.empty();
     socialApp.Controller.layout.content.empty();
     socialApp.Controller.layout.footer.empty();
    }

what I do is correct? any one confirm me please? Note : Do I need to close the controller / views as well..!? I am using Backbone.Marionette v2.1.0. Thanks in advance.

Upvotes: 2

Views: 4496

Answers (1)

emem
emem

Reputation: 151

From Marionette v2.1.0 Region docs

If you replace the current view with a new view by calling show, by default it will automatically destroy the previous view.

From LayoutView

After the first render, all subsequent renders will force every region to be emptied by calling the empty method on them. This will force every view in the region, and sub-views if any, to be destroyed as well.

Thus I think you don't need to empty() them manually

Upvotes: 6

Related Questions