Skip to main content

non-emptying.region

NonEmptyingRegion : d2/sdk/controls/regions/non-emptying.region

A Marionette.Region that does not empty it's DOM element on rendering new instance of Marionette.View.

Extends: Marionette.Region
Example

define([
'nuc/lib/underscore',
'nuc/lib/marionette',
'd2/sdk/controls/regions/non-emptying.region'
], function(_, Marionette, NonEmptyingRegion){
'use strict';

var MyView = Marionette.LayoutView.extend({
template: false,
constructor: function MyView(options) {
options = options || {};
MyView.__super__.constructor.call(this, options);
},

onRender: function() {
if(_.isString(this.options.greet) && !_.isEmpty(this.options.greet)) {
this.$el.text(this.options.greet);
}
}
});

var view1 = new MyView({greet: 'Hello'});
var view2 = new MyView({greet: 'World'});

var region = new NonEmptyingRegion({el: '.host-element'}); //can also set prependChild: true if element for view added later should show before previously added element in DOM.

region.show(view1); //Adds element with 'Hello' in the DOM
region.show(view2, {preventDestroy: true}); //Adds element with 'World' in the DOM, however element with 'Hello' is not removed and still exists in the DOM.

//With normal Marionette.Region, after adding view2, the HTML element specific to view1 would have been removed.
});

nonEmptyingRegion.show(view, [options])

Shows a Marionette.View in the region.

Kind: instance method of NonEmptyingRegion

ParamTypeDescription
viewMaionette.View

The view to be shown

[options]object

Display control options

[options.preventDestroy]Boolean

Indicates whether previous view should be destroyed before showing current view or not. This flag is an important indication that tells the NonEmptyingRegion to keep adding view content as children of it own element. Without this flag seto to truethe previously shown view is destroyed and its element is removed from DOM as usual.

NonEmptyingRegion~NonEmptyingRegion

Kind: inner class of NonEmptyingRegion

new NonEmptyingRegion([options])

ParamTypeDescription
[options]object

Constructor options. Usual constructor options as per Marionette.Region specification are all supported but not explictly documented here. Below are the special parameter supported by this region type.

[options.prependChild]Boolean

Flag to indicate whether current view's element is to be placed before or after previous view's element in DOM when show() is called with options.preventDestroy=true. Defaults to false.

[options.index]number

Positive integer to indicate any specific ordered spot for current view's element in the DOM when a previous view exists and current view is being shown with options.preventDestroy=true.