Is this pattern correct for performing region switching with Marionette?
pThis question is based on my previous one a
href=http://stackoverflow.com/questions/17976750/switching-from-a-region-to-another-in-marionette-views-are-not-rendered-correctSwitching
from a region to another in Marionette, views are not rendered
correctly/a. It differs from it since I'm asking if the approach I'm
following is correct or it exists another approach to perform the
switching between regions./p pI've created a layout with two different
regions. On codeinitialize/code the layout loads two views in two regions
of my layout. Say codeViewA/code and codeViewB/code. Within codeViewA/code
an event is triggered. The event is consumed by the layout to switch and
other two views are injected. Say codeViewC/code and codeViewD/code./p pIs
this approach correct or do I have to follow another pattern? Routing?/p
pHere some code where comments highlight the important parts./p
precodeonConfirm : function() { this.leftView = new ViewC();
this.rightView = new ViewD(); this.leftRegion.show(this.leftView);
this.rightRegion.show(this.rightView); }, initialize : function() { //
listen for event triggered from ViewA // e.g.
GloabalAggregator.vent.trigger(ga:confirm); // where ga:confirm is a
simple string GloabalAggregator.vent.on(ga:confirm , this.onConfirm,
this); this.leftView = new ViewA(), // creating here a new ViewC the style
is applied correctly this.rightView = new ViewB(); // creating here a new
ViewD the style is applied correctly }, onRender : function () {
this.leftRegion.show(this.leftView);
this.rightRegion.show(this.rightView); } /code/pre
No comments:
Post a Comment