Petter Kjelkenes
Petter Kjelkenes

Reputation: 1625

Backbone Marionette, Render Region if not already rendered

So I want to render a sidemenu itemview only if it's not rendered already. This is so unessecary I don't force unessecary re-rendering.

I have figured a solution to render a view if not rendered in a region already.

Take the following example in a controller object called by a router.:

Admin.showIndex= function(){
    if (!MyApp.layout.sidepanel.currentView || !(MyApp.layout.sidepanel.currentView instanceof AdminSidePanel)){
        MyApp.layout.sidepanel.show(new AdminSidePanel());
    }else{
        alert("Already rendered sidepanel!");
    }
    // More stuff!
}

Is this a good way to do it? It works like this:

Upvotes: 1

Views: 740

Answers (1)

Tony Abou-Assaleh
Tony Abou-Assaleh

Reputation: 3040

Looks good to me. I've used similar logic in my project.

I prefer this approach over explicitly maintaining a global state variable in MyApp.

Upvotes: 2

Related Questions