View Adapter Definition Structure

A view adapter definition is defined as a JavaScript object containing one or more of three root properties. Those root properties arecontrols,eventsandmembers. Additionally, one or more initializers may be defined as root properties on inline child control definitions under thecontrolsproperty.

Note that initializers cannot be defined for the root of a view adapter definition. Initializers are intended to be defined in parent definitions for child controls where they are declared regardless of whether or not the child control structure is fully defined inline or defined in a separate view adapter definition (via either theadapterorfactoryoption properties). Any initialization the developer wants to include for the root of the view adapter definition can be performed inside of theconstructmethod within themembersstructure.

Example:

!function()
{"use strict";root.define("acme.exampleViewAdapter",
function(reusableControlAdapter, anotherReusableControlFactory)    // <-- dependencies are injected here
{return function exampleViewAdapter(viewAdapter)                   // <-- viewAdapter is a reference to the root view adapter instance assembled from the adapterDefinition returned by this class
{
    var adapterDefinition   =
    {
        controls:
        {
            exampleInlineChildControl:
            {
                controls:   {},
                events:     [],
                members:    {},
                onclick:    function() { alert("The exampleInlineChildControl was clicked"); }
            },
            exampleAdapterChildControl:
            {
                adapter:    reusableControlAdapter
            },
            exampleChildControlFromFactory:
            {
                factory:    anotherReusableControlFactory
            }
        },
        events: ["customEvent1", "customEvent2"],
        members:
        {
            construct:
            function()
            {
                this.addEventListener("click", function(event){ alert("This view adapter was clicked."); });
            },
            customMethod1:
            function(parameter1)
            {
                alert("The customMethod1 method of the view adapter was called with " + parameter1);
            }
        }
    }

    return adapterDefinition;
}});}();

results matching ""

    No results matching ""