Skip to main content

layoutview.events.propagation.mixin

LayoutViewEventPropagationMixin : d2/sdk/controls/mixins/layoutview.events.propagation.mixin

Event propagation mixin for Marionette LayoutView. Marionette Layout view fails to propagate view-lifecycle events to different child views that it hosts in its regions. This mixin makes it possible to establish the broken chain in a declarative style.

Extends: Object
Example (To use the mixin in a layout view)

define([
'nuc/lib/marionette',
'd2/sdk/controls/mixins/layoutview.events.propagation.mixin',
], function(Marionette, LayoutViewEventsPropagationMixin){
'use strict';

var MyView = Marionette.LayoutView.extend({
regions: {
header: '.header',
footer: '.footer'
},
constructor: function MyView(options) {
options = options || {};
MyView.__super__.constructor.call(this, options);

this.propagateEventsToRegions();
}
});

LayoutViewEventsPropagationMixin.mixin(MyView.prototype);

var view = new MyView();
new Marionette.Region({el: '.host-element'}).show(view); // With this default setup, whenever MyView instance receives 'dom:refresh' event, it is also relayed to views hosted in regions 'header' & 'footer'.
});

layoutViewEventPropagationMixin._eventsToPropagateToRegions : Array.<string>

This property gets mixed with the view prototype. It should contain a list of Marionette view lifecycle events that are desired to be propagated to each hosted child view when those events occur at the LayoutView level.

Kind: instance property of LayoutViewEventPropagationMixin
Default: ['dom:refresh']

layoutViewEventPropagationMixin.propagateEventsToRegions() ⇒ void

This method gets mixed with any Marionette.View prototype. This method should be called from within a view instance post construction.

Kind: instance method of LayoutViewEventPropagationMixin

LayoutViewEventPropagationMixin.mixin(prototype) ⇒ void

Method to add this mixin to a view prototype.

Kind: static method of LayoutViewEventPropagationMixin

ParamTypeDescription
prototypeany

The view prototype where is mixin is to be merged.