Skip to main content

widget.view.state.mixin

WidgetViewStateMixin : d2/sdk/controls/mixins/widget.view.state.mixin

Mixin to faciliate storage and retrieval of view specific parameters especially for those views that are backed by a widget configuration.

To be mixed on the prototype of a view.

Extends: Object
Example

define([
'nuc/lib/marionette',
'd2/sdk/controls/mixins/widget.view.state.mixin',
'd2/sdk/utils/contexts/context.utils'
], function(Marionette, WidgetViewStateMixin, contextUtil){
'use strict';

var MyView = Marionette.ItemView.extend({
constructor: function MyView(options) {
options = options || {};
this.context = contextUtil.getPerspectiveContext(); //A context reference on self object is required for WidgetViewStateMixin to work.
MyView.__super__.constructor.call(this, options);
},

onRender: function() {
this.$el.text('My widget name is: ' + this.getViewStateWidgetName());
}
});

WidgetViewStateMixin.mixin(MyView.prototype);

var view = new MyView();
view.setViewStateWidgetName('hello world'); //Also, the view itself could call it to set the value

new Marionette.Region({el: '.host-el'}).show(view); //Shows the widget name in view element's text.
});

widgetViewStateMixin.setViewStateWidgetName(widgetName) ⇒ void

Set the widget configuration name to be associated with this widget.view

Kind: instance method of WidgetViewStateMixin

ParamTypeDescription
widgetNamestring

Stores the supplied value against key widget-name in the ViewStateModel

widgetViewStateMixin.getViewStateWidgetName() ⇒ string | undefined

Get the widget configuration name associated with this widget.view

Kind: instance method of WidgetViewStateMixin
Returns: string | undefined - previously stored widget name from ViewStateModel

widgetViewStateMixin.getInitialUrlParamsList() ⇒ Array.<string>

Get the initial list of parameters to be serialized/deserialized from the HTML document location

Kind: instance method of WidgetViewStateMixin
Returns: Array.<string> - should return name of the parameter to (de)serialize from the HTML page URL

WidgetViewStateMixin.mixin(prototype) ⇒ *

Mix function from this mixin into supplied prototype.

Kind: static method of WidgetViewStateMixin
Returns: * - The same prototype

ParamTypeDescription
prototypeany

A view prototype.